How to delete folder using CMD in Windows

How to delete folder using CMD in Windows

It’s sometimes just quicker to perform things from the command line. In this fast tutorial, we will discuss how to start Command Prompt and some basic commands and parameters. Feel free to move forward if you’re already comfortable with fundamental DOS commands. Find below the steps to know “How to delete folder using CMD in Windows”.

Open Command Prompt

To open Command Prompt, press the Windows key and type “cmd.”

Then select “Run as Administrator”.

How to delete folder using CMD

After that, you’ll be presented with an administrative Command Prompt window.

How to delete folder using CMD

Don’t worry if you can’t open Command Prompt as an administrator. Instead of “Run as Administrator,” you can select “Start” to open a regular Command Prompt window.

The only difference is that some protected files may not be deleted, which should not be a problem in most instances.

Read More:- What Is HTTP Error 503 Service Unavailable and How to Fix It?

Delete files with the del command

Use cd to move directories to where your files are now that Command Prompt is open.

On my desktop, I’ve created a directory called Test Folder. You may see a tree of all the nested files and directories with the command tree /f:

How to delete folder using CMD

Use the following command to delete a file: “del” is a command that deletes a file.

Use del “Test File.txt” to delete Test file.txt, for example.

There’s a chance you’ll be asked if you want to delete the file. If this is the case, press enters and type “y.”

Note that any files deleted with the del command are lost forever. Execute considerable caution when deciding where and how to use this command.

After that, you can use tree /f to see if your file was successfully deleted:

How to delete folder using CMD

Bonus tip: Command Prompt includes basic autocompletion. So if you input the test, then the Prompt command will change it into the “Test File.txt.” key.

How to force the command del removal of files

When you try to use the del command on a file that has been marked as read-only, you’ll get the following error.

How to delete folder using CMD

Use the /f flag to force delete the file to get around this. del /f “Read Only Test File.txt,” as an example.

How to delete folder using CMD

Delete folders with the rmdir command

The rmdir or rd commands are used to delete directories and folders. Both commands achieve the same objective, however, we are going to use rmdir because it is more expressive.

For the rest of the lesson, I will use the terms folder and directory interchangeably. Folder and directory are fundamentally the same thing, despite the fact that “folder” is a relatively contemporary moniker that gained favor with early desktop GUIs.

Use the command rmdir directory name> to remove a directory.

Note” Any folders erased using the rmdir command are irreversibly lost. Use this command with extreme caution in where and how you use it.

I will use the rmdir subfolder command in this instance to delete a subfolder called:

How to delete folder using CMD

However, as you may recall, Subfolder contains a file titled Nested Test File.

You could cd into the Subfolder directory and delete the file, then cd.. and repeat the rmdir Subfolder command again, but that’s a pain. Consider what would happen if there were a zillion more nested files and directories!

Like the del command, we can add a useful flag to make it much quicker and easier.

How to use the /s flag with rmdir

Simply use the /s flag to remove a directory, including all nested files and subdirectories:

How to delete folder using CMD

A prompt will most likely ask if you wish to remove that directory. If that’s the case, simply type “y” and press enter.

That’s all there is to it! That should cover everything you need to know about deleting files and folders using the Windows Command Prompt.

PowerShell, which is essentially Command Prompt 2.0, should work with all of these commands. Also, if you’re familiar with the Mac/Linux command line, PowerShell includes a variety of fun aliases like ls and clear that should feel right at home.

Have these commands been beneficial for you? Do you have any more commands that are helpful to you? In any case, please let me know on The commend box.

Back to top
%d bloggers like this: