rd
删除一个目录,这个命令和rmdir是一样的。
格式
rd [<Drive>:]<Path> [/s [/q]]
参数
参数 | 描述 |
---|---|
[<Drive>:] | 要删除的目录路径 |
/s | 删除目录树。 (目录及其子目录,包括所有的文件) |
/q | 安静模式 。删除一个目录树的时候不询问确认。 (注意 /q 仅在同时使用 /s 时有效) |
/? | 显示帮助信息。 |
Remarks
-
不能删除有文件的文件夹,包括隐藏文件和系统的文件的情况。如果你尝试这么做,将会出现以下错误信息:
The directory is not empty
Use the dir /a command to list all files (including hidden and system files). Then use the attrib command with -h to remove hidden file attributes, -s to remove system file attributes, or -h -s to remove both hidden and system file attributes. After the hidden and file attributes have been removed, you can delete the files.
-
在Path的开始处使用反斜杠字符,路径将会从根目录开始(不管当前目录是什么)
-
不能使用rd删除当前目录。如果你尝试删除当前目录,将会出现以下错误信息:
The process cannot access the file because it is being used by another process.
If you receive this error message, you must change to a different directory (not a subdirectory of the current directory), and then use rd (specify Path if necessary).
-
在恢复控制台可以使用rd命令。
Examples
不能删除当前目录。必须先切换到当前目录之外才可以。例如可以切换到父目录:
cd ..
现在你可以删除你想要删除的目录。
使用/s选项删除一个目录树. 例如,删除一个名为test的目录(以及它的子目录和文件) from the current directory, type:
rd /s test
对于上面的例子使用安静模式运行:
rd /s /q test
注意
如果使用在安静模式下运行rd /s,整个目录树会在没有询问确认的情况下删除。请保证在使用/q选项前将重要的文件已经移动或备份。