How To Delete Files & Folders – From The Windows Command Line (CMD, DOS)

What We'll Learn:

This guide is all about deleting files and folders from the windows command line.

  • We’ll start by learning, how to navigate the file or folder we want to delete form the command prompt.
  • How to use the Del and Rmdir commands to remove files and folders respectively.
  • How to take advantage of wildcards to perform an operation on multiple files or directories.
  • And finally, we’ll learn how to delete files and folders without navigating to the directory in which they are located.

Lets get started!

Navigating To The File We want to delete - Using CMD:

Before we can delete our file/folder we must first navigate to its location from the command prompt (cmd). Here is how:

By default the command line is located at a folder named after your computers username: C:\Users\Username. This folder contains, among others, your documents, downloads and desktop directories.

First, we need to view all the files in this directory so that we know where to navigate from here. To do so simply use Dir.


Dir stands for directory, and it displays every file and folder in the current directory.

From here use the cd command to navigate to the directory of the file or folder you want to delete.  For example if the file or folder you want to delete is located at your desktop, type the following:

Cd "Desktop"

Replace “Desktop” with the directory of your choice. From here you can use the “Dir” command once again to locate the file or folder you want to delete.

If you navigated to the wrong directory by mistake, type:

CD ..

You will immediately be navigated into the previous directory.

In a similar way you can use a combination of the “Dir” and “Cd” commands to navigate to any directory and locate any file or folder.

Delete a Folder / Directory - Using CMD​

If the item you want to delete is a folder/directory you need to use the Rmdir command to delete it. Rmdir stands for “Remove Directory”.

As the name suggests, Rmdir only deletes directories. Trying to delete a file using “Rmdir” will constitute in an error.

Empty Folders:

To delete an empty folder type Rmdir followed by the name of your folder/directory within quotes.

Rmdir "My Folder"

You might be wondering why we surrounded the name of our folder in quotes. The quotes tell the command prompt that the spaces separating the words do not constitute an additional parameter and that they are simply a part of the name of our folder. 

Directories with files within them:

Rmdir without any parameters only removes folders that are empty, to forcefully delete a folder along with along with any files or folders within it you need to use the /S parameter. Here is what that looks like:

Rmdir /S "My Folder"

The command prompt will ask if you are sure you want to delete this file. Simply press “y” to confirm.

If you want to delete a folder in a directory other than your users folder you would need to start the command prompt as an administrator.

Be careful when deleting folders as an administration, the wrong command can very easily break your computer.

Delete A File - Using CMD​

To delete any type of file from the command prompt we need to use the Del command. Unlike Rmdir, Del can only delete files. Using Del to delete a folder will constitute in an error.

Using the Del command to Delete a file:

To delete a file simply type Del followed by the name of your file along with its extension in quotes.

Del "My File.txt"

Your file will be immediately deleted.

Once again if you file is not located in the users directory or within any of its sub-directories you would need to start the command prompt as an administrator. 

Be very careful however , the wrong command in an elevated command prompt can very easily break your computer.

Force Delete A file:

While the above command will work in most cases, oftentimes files refuse to be deleted. Thankfully we can force the dell command to delete our file simply by using the /f parameter.
Here is what that would look like:

Del /f "My File.txt"

Its as simple as that!

Delete Multiple Files:

To delete more than one file at once simply enter all the names of your files one after the other.

Del "File1.txt" "File2.txt" "File3.txt"

All of your files will be deleted at once. Awesome, right?

Play Video

There's an easier way!

Learn the ins and outs of the windows command line with our windows command line course.

Delete Many Files Or Folders At Once​ - From CMD

Entering the name of every file or folder you want to delete is not always practical. Work smarter not harder!

Instead, you can delete multiple files or folders at once by using a wildcard. Wildcards are special symbols that take the place of characters or words. The most commonly used wildcard is the asterix.

Delete Files/folders with a specific word:

Typing a set of characters that is shared among the names of the files we want to delete followed by an asterix, will delete all of them.

Del "File*"
Rmdir /S "Folder*"

Every file or folder that begins with the word “File” or “Folder” respectively, will be deleted. 

Delete Files with a specific Extension:

Similarly you can delete only files of a specific type by specifying its extension before a wildcard. With the following command for example, we can delete every text file in our current directory.

Del "*.txt"

Awesome. isn’t it?

Delete Every File/Folder in a directory:

We can even delete every file or folder by using a wildcard, all by itself.
Here is an example using the Rmdir command:

Rmdir /S "*"

Every folder in your current directory will be deleted along with any contents within it.

You can do the same with the Del command as well:

Del "*"

Be careful when deleting files and folders, the wrong command can easily delete important files and folders.

Delete Files Or Folders From Any Directory​ (CMD)

While you can use the “Rmdir” and “Del” commands to delete files and folders in your current directory, what if you want to delete a folder or file that’s located in a different directory without having to navigate there yourself?

You would have to enter your command as usual but instead of typing the name of the file or folder you want to delete directly you would have to enter the location of the target directory followed by a backward slash and then name of your folder or file. It should look something like this:

Rmdir "C:\Users\Julian\Documents\My Folder".

In the same way you can replace “Rmdir” with any command to complete any task from any directory.


  • Navigate to the directory the file you want to delete is located with the “CD” and “Dir” commands.
  • Use “Rmdir” to delete folders and “Del” to delete files. Don’t forget to surround the name of your folder in quotes if it contains a space.
  • Use wildcards to delete many files or folders at once.

That's It!

You now know how to delete files and folders directly from the command prompt.

If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.

Play Video
Dont Stop Learning!

Windows Command Line Course!

This course has everything you need to start learning about the windows command line along with batch scripting.

Read More:

Any Questions? Ask them Below:

Leave a Reply

Your email address will not be published.

Take Your Skills to the next level!
Become one of our beloved students by enrolling into one of our courses. Get started now!


Take A Look At Our Command Line Course!

Need Help?

There's an easier way!


You are now officially on your way to becoming a genius!