Remove 'C:\source_files' but only if it is already empty: Remove 'C:\demo documents\work' and all files and sub folders: If you delete directories using PowerShell then a True/False return code ( $?) will be set correctly. RD NonExistentFolder || Echo This failed! In normal use RD will fail to return an ERRORLEVEL to the shell, irrespective if the command succeeds or fails the ERRORLEVEL will be left unchanged.Ī workaround to detect a non zero Exit Code from RD is to use conditional execution to run a command if the RD fails, the second command can be anything, but typically will be an Echo, Goto or CALL statement: If you try to delete a directory which has a trailing space, WIndows explorer will give the error: “Could Not Find This Item”.Įscaping the closing quote seems to bypass the normal logic of trimming trailing spaces and allows you to delete the folder:Ĭ:\> RD "this has a trailing space \" Exit code / Errorlevel RD does not support wildcards but you can remove multiple directories in one command:Ĭ:\> RD C:\docs\Jan "C:\My Documents\Mar" Delete a directory with a trailing space If the pathname is a Junction Point, then RD without /S will remove the Junction point itself, not the Junction’s destination directory. RD /Q will silently fail to delete any directories that are not empty. Without the /S option, RD will only delete an empty directory and Place any long pathnames in double quotes. Q : Quiet - do not display Y/N confirmation Use this to remove an entire folder tree.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |