rdrd

刪除目錄。Deletes a directory.

Rd 命令也可以使用不同的參數,從 Windows 修復主控台執行。The rd command can also run from the Windows Recovery Console, using different parameters. 如需詳細資訊,請參閱 Windows 修復環境 (WinRE) For more information, see Windows Recovery Environment (WinRE).

注意

此命令與 rmdir 命令相同。This command is the same as the rmdir command.

語法Syntax

rd [<drive>:]<path> [/s [/q]]

參數Parameters

參數Parameter 描述Description
[<drive>:]<path> 指定您想要刪除之目錄的位置和名稱。Specifies the location and the name of the directory that you want to delete. 需要 路徑Path is required. 如果您在 ) 指定 路徑 的開頭包含反斜線 (,則 路徑 會在根目錄 (開始,無論目前目錄) 為何。If you include a backslash () at the beginning of the specified path, then the path starts at the root directory (regardless of the current directory).
/s/s 刪除指定目錄及其所有子目錄 (的目錄樹狀結構,包括) 的所有檔案。Deletes a directory tree (the specified directory and all its subdirectories, including all files).
/q/q 指定安靜模式。Specifies quiet mode. 刪除樹狀目錄時,不會提示確認。Does not prompt for confirmation when deleting a directory tree. /Q 參數只有在同時指定 /s 時才能運作。The /q parameter works only if /s is also specified.

注意: 當您以無訊息模式執行時,系統會刪除整個目錄樹狀結構,而不進行確認。CAUTION: When you run in quiet mode, the entire directory tree is deleted without confirmation. 使用 /q 命令列選項之前,請務必移動或備份重要的檔案。Make sure that important files are moved or backed up before using the /q command-line option.

/?/? 在命令提示字元顯示說明。Displays help at the command prompt.

備註Remarks

  • 您無法刪除包含檔案的目錄,包括隱藏的檔案或系統檔案。You can't delete a directory that contains files, including hidden or system files. 如果您嘗試這麼做,則會出現下列訊息:If you attempt to do so, the following message appears:

    The directory is not empty

    使用 dir/a 命令列出所有檔案 (包括隱藏和系統檔案) 。Use the dir /a command to list all files (including hidden and system files). 然後使用 attrib 命令搭配 -h 來移除隱藏的檔案屬性、 -s 以移除系統檔案屬性,或使用 -h-s 來移除隱藏的和系統檔案屬性。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.

  • 您無法使用 rd 命令刪除目前的目錄。You can't use the rd command to delete the current directory. 如果您嘗試刪除目前的目錄,則會出現下列錯誤訊息:If you attempt to delete the current directory, the following error message appears:

    The process can't 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 try again.

範例Examples

若要變更為上層目錄,讓您可以安全地移除所需的目錄,請輸入:To change to the parent directory so you can safely remove the desired directory, type:

cd ..

若要從目前目錄中移除名為 test (的目錄及其所有子目錄) 和檔案,請輸入:To remove a directory named test (and all its subdirectories and files) from the current directory, type:

rd /s test

若要以安靜模式執行上述範例,請輸入:To run the previous example in quiet mode, type:

rd /s /q test

其他參考Additional References