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 CommandFor 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.
Using ‘/s’ flag with rmdirFor 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 DirectoryFor 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:
- Basic Windows CMD commands
- Cool CMD Commands Tips and Tricks
- Best CMD Commands for Hacking
- CMD Commands for Wireless Network Speed
- Useful Keyboard Shortcuts for CMD
- What Info about My Laptop Can I Check with CMD and How?
- Getting Started with CMD Windows
- TOP-12 Command-Line Interview Questions (Basic)
- Command-Line Interview Questions (Advanced)
- CMD Commands to Repair Windows
- CMD Commands to Speed Up Computer
- CMD Commands for MAC OS
- How Does the Command Line Work?
- MS-Dos Interview Questions in 2021
- Windows OS Versions and History
- Recent Windows Versions Compared
- Basic Windows Prompt Commands for Every Day
- Windows Command Line Cheat Sheet For Everyone
- Windows Command Line Restart
- Windows Command Line for Loop
- Windows Command - Change Directory
- Windows Command - Delete Directory
- Windows Command Line – Set Environment Variable