Link Search Menu Expand Document

Windows Command Line – Delete Directory

The windows command line or text interface is a kind of user interface that can be controlled by passing commands in the form of prompts instead of using a mouse. Command-line is different from GUI OS, i.e., Graphical User Interface Operating System. It only needs a keyboard to control and navigate by passing the commands instead of a mouse.

For example, to open the windows folder in the windows command line, we use “C:\Windows”.</p.

However, using the command line requires one to remember lots of commands. Still, it is beneficial which should not be ignored. Command-line allows a user to perform all the tasks that they can perform on a GUI OS. And sometimes, there are many tasks that we can accomplish even quicker than GUI OS, and they are straightforward to automate as well.

For example, if a person is asked to rename 50 files in a folder at a time. So, setting an environment variable with GUI can be very time-consuming but with the help of the windows command line, this can be done in seconds by passing a single command using a batch file or other scripts.

How to remove Directories using Command-Line?

To delete files or folders from your computer using the command line, you first have to open the command prompt and select the option as ‘Run as Administrator. The command window will open. For removing any directory from your PC, ‘rmdir’ is the central Command used in the command line. It is used to delete folders and their contents.

Deleting folders with rmdir Command

For removing any directory or folder, either rrmdir or rd command can be used, and both the commands work in the same way. But mainly, rmdir is used because it is more expressive than rd.
  • To delete any directory, the Command which should be used is – rmdir <directory name>.
  • For instance, if there is a folder named Alpha, so for removing that folder, the Command which is supposed to be passed is – rmdir Alpha.
  • The drawback of using this Command is that once a directory or folder is deleted, it cannot be recovered. So, users need to be very cautious while using the command line.
But have you thought about how to delete a folder that has nested files in it? So, we have a flag that makes such things much faster and easier for removing those directories and folders.

Using ‘/s’ flag with rmdir

For removing the directories or folders with nested files or sub-directories, a user has to use the /s flag. Before removing the folder, there will be a confirmation message if the user wants to delete the directory. In that case, the user has to type ‘Y’ and then press enter, and the folder will be deleted.

Now, what if someone wants to delete only the nested files or the sub-directories in the folder or directory. In that case, we have a different command.

Removing Contents of Directory without removing the parent Directory

For deleting the content of a directory, without deleting the whole directory, a user cannot use rmdir because it permanently removes the parent directory. So, for deleting only the directory content by keeping the parent directory, the command ‘isdir’ can be used with the same syntax.

Other useful articles:


Back to top

© , CMD Windows — All Rights Reserved - Terms of Use - Privacy Policy