Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/future4tech/public_html/wp-includes/functions.php on line 6114
RD – Windows CMD Command - Future4Tech

RD – Windows CMD Command

Remove (or Delete) a Directory.

Syntax
      RD pathname
      RD /S pathname
      RD /S /Q pathname
   
Key
   /S  : Delete all files and subfolders
         in addition to the folder itself.
         Use this to remove an entire folder tree.

   /Q  : Quiet - do not display Y/N confirmation

Place any long pathnames in double quotes.

Without the /S option, RD will only delete an empty directory and RD /Q will silently fail to delete any directories that are not empty.
If the pathname is a Junction Point, then RD without /S will remove the Junction point itself, not the Junction’s destination directory.

RD does not support wildcards but you can remove multiple directories in one command:

RD C:\docs\Jan “C:\My Documents\Mar”

Exit code / Errorlevel

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.

It will however set an Exit Code

Directory deleted successfully = 0
Invalid option = 1
Directory not found = 2
Access denied = 5
Directory in use = 32
Directory not empty = 145

A 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:

RD NonExistentFolder || Echo This failed!

If you delete directories using PowerShell then a True/False return code ($?) will be set correctly.

RMDIR is a synonym for RD

RD is an internal command.

Examples

Remove 'C:\demo documents\work' and all files and sub folders:

RD /S "C:\demo documents\work"

Remove 'C:\source_files' but only if it is already empty:

RD "C:\source_files"

You may also like...

6 Responses

  1. zoritoler imol says:

    Thank you for every other informative web site. Where else could I get that type of info written in such an ideal method? I’ve a undertaking that I’m just now working on, and I’ve been at the look out for such info.

  2. zoritoler imol says:

    You are a very intelligent individual!

  3. Marty says:

    Aw, this was a really nice post. Taking the time and actual effort to create a superb article… but what can I say… I hesitate a whole lot and never seem to get
    anything done.

  4. Leonore says:

    Thanks for your marvelous posting! I certainly enjoyed reading
    it, you’re a great author. I will make certain to bookmark
    your blog and will come back at some point. I want to encourage yourself to continue your great job, have a nice weekend!

  5. zortilonrel says:

    Regards for helping out, wonderful info. “The laws of probability, so true in general, so fallacious in particular.” by Edward Gibbon.

  6. froleprotrem says:

    I know this if off topic but I’m looking into starting my own blog and was wondering what all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web savvy so I’m not 100 positive. Any suggestions or advice would be greatly appreciated. Kudos

Leave a Reply

Your email address will not be published. Required fields are marked *


Notice: ob_end_flush(): Failed to send buffer of zlib output compression (0) in /home/future4tech/public_html/wp-includes/functions.php on line 5464