Windows cmd delete all folder

cmd Delete Folder – How to Remove Files and Folders in Windows

Kris Koishigawa

Sometimes it’s just faster to do things with the command line.

In this quick tutorial we’ll go over how to open Command Prompt, some basic commands and flags, and how to delete files and folders in Command Prompt.

If you’re already familiar with basic DOS commands, feel free to skip ahead.

How to open Command Prompt

To open Command Prompt, press the Windows key, and type in «cmd».

Then, click on «Run as Administrator»:

After that, you’ll see a Command Prompt window with administrative privileges:

Screenshot of Command Prompt window

If you can’t open Command Prompt as an administrator, no worries. You can open a normal Command Prompt window by clicking «Open» instead of «Run as Administrator».

The only difference is that you may not be able to delete some protected files, which shouldn’t be a problem in most cases.

How to delete files with the del command

Now that Command Prompt is open, use cd to change directories to where your files are.

I’ve prepared a directory on the desktop called Test Folder. You can use the command tree /f to see a, well, tree, of all the nested files and folders:

To delete a file, use the following command: del » » .

For example, to delete Test file.txt , just run del «Test File.txt» .

There may be a prompt asking if you want to delete the file. If so, type «y» and hit enter.

Note: Any files deleted with the del command cannot be recovered. Be very careful where and how you use this command.

After that, you can run tree /f to confirm that your file was deleted:

Also, bonus tip – Command Prompt has basic autocompletion. So you could just type in del test , press the tab key, and Command Prompt will change it to del «Test File.txt» .

How to force delete files with the del command

Sometimes files are marked as read only, and you’ll see the following error when you try to use the del command:

To get around this, use the /f flag to force delete the file. For example, del /f «Read Only Test File.txt» :

How to delete folders with the rmdir command

To delete directories/folders, you’ll need to use the rmdir or rd command. Both commands work the same way, but let’s stick with rmdir since it’s a bit more expressive.

Also, I’ll use the terms directory and folder interchangeably for the rest of the tutorial. «Folder» is a newer term that became popular with early desktop GUIs, but folder and directory basically mean the same thing.

To remove a directory, just use the command rmdir .

Note: Any directories deleted with the rmdir command cannot be recovered. Be very careful where and how you use this command.

In this case I want to remove a directory named Subfolder, so I’ll use the command rmdir Subfolder :

But, if you remember earlier, Subfolder has a file in it named Nested Test File.

You could cd into the Subfolder directory and remove the file, then come back with cd .. and run the rmdir Subfolder command again, but that would get tedious. And just imagine if there were a bunch of other nested files and directories!

Like with the del command, there’s a helpful flag we can use to make things much faster and easier.

Читайте также:  Драйвера для samsung n100 windows

How to use the /s flag with rmdir

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

There will probably be a prompt asking if you want to remove that directory. If so, just type «y» and hit enter.

And that’s it! That should be everything you need to know to remove files and folders in the Windows Command Prompt.

All of these commands should work in PowerShell, which is basically Command Prompt version 2.0. Also, PowerShell has a bunch of cool aliases like ls and clear that should feel right at home if you’re familiar with the Mac/Linux command line.

Did these commands help you? Are there any other commands that you find useful? Either way, let me know over on Twitter.

Kris Koishigawa

Read more posts by this author.

If you read this far, tweet to the author to show them you care. Tweet a thanks

Learn to code for free. freeCodeCamp’s open source curriculum has helped more than 40,000 people get jobs as developers. Get started

freeCodeCamp is a donor-supported tax-exempt 501(c)(3) nonprofit organization (United States Federal Tax Identification Number: 82-0779546)

Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons — all freely available to the public. We also have thousands of freeCodeCamp study groups around the world.

Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and staff.

How To Delete a Folder Using Command Prompt of Windows

To delete a folder using command prompt of windows, follow this procedure.

  1. Open a command prompt (Press the windows icon key and R to open the run window). Type cmd and hit enter from the keyboard.
  2. On a command prompt, enter the following command and hit enter from the keyboard.

When your path contains spaces, then the path must be enclosed in quotation marks.

28 thoughts on “How To Delete a Folder Using Command Prompt of Windows”

Thanks ! It worked for me !

100% spot-on – THNX

C:\Users\Marcel2>cd ..\..\Program Files
C:\Program Files>rmdir /s EqualizerAPO
EqualizerAPO, Are you sure (Y/N)? y
EqualizerAPO\EqualizerAPO.dll – Access is denied.
EqualizerAPO\libfftw3f-3.dll – Access is denied.
EqualizerAPO\libsndfile-1.dll – Access is denied.
EqualizerAPO\msvcp120.dll – Access is denied.
EqualizerAPO\msvcr120.dll – Access is denied.
Access is denied.

Try running the command from a console with administrative privileges.

open cmd as run as administrator

Right click and run command prompt as administrator

try running cmd as an administrator this will fix your problem

I followed your steps completely, yet I still get an error (“…” is in the place of sensitive information, my real name is the user, with a space in between):

C:\WINDOWS\system32>rmdir /s C:\Users\…\AppData\Local\Discord
C:\Users\…, Are you sure (Y/N)? Y
The system cannot find the file specified.
…\AppData\Local\Discord, Are you sure (Y/N)? Y
The system cannot find the path specified.

Does the folder really exist in that path?

how to set it automatically, it will delete folder for more than 2 days

C:\Program Files (x86)>rmdir /s Epic Games
Epic, Are you sure (Y/N)? y
The system cannot find the file specified.
Games, Are you sure (Y/N)? y
The system cannot find the file specified.

if you need to delete a folder that has spaces in the name then you need to encompass the full path in quotation marks “”, windows sees the space as a break in the command and thinks the next thing after it is another command, but by surrounding the full path in quotation marks “” it reads the full path within them, spaces included, so it should look like below

rmdir /s “c:\Program Files\folder name”

do c:\ first then run the command rmdir /s Epic Games
It will look like c:\ rmdir /s Epic Games

rmdir /s /q
The syntax of the command is incorrect.

What am i doing wrong

You have to specify the path of the folder that shall be deleted. Please see the tutorial above for examples.

The process cannot access the file because it is being used by another process.

Same it is not working for me. Windows 10

Stop the application that is using the file before you delete the file.

I chose “run as admin” and entered the prompt,
typed: rmdir /s E:\Lixo
still access denied
I’m trying to delete the “windows” folder from an old hd
any tips?
Cheers

Читайте также:  Установка windows 10 как выбрать диск для установки

Fail: cmd as admin, still “access denied”

Got same error saying access denied even after running the command with administrative privileges.

Yeah ! This command is running easily .

yes i did but not working

Thanks so much for your instructions. I had been to other sites, looking for instructions on how to delete a folder in the Command Prompt that I could not delete by right clicking and selecting delete. I kept getting “The system can not find the file specified.” or “The system can not find the path specified.” Your site was the only one which explained that you have to enclose the path in quotation marks, if there are any spaces. That was my problem. One of the folders in the path had a space in the title.

I ran the program both with command prompt and as a system administrator but it did not work yet. access denied
C:\Windows\system32>rmdir /s “C:\Users\USER\Downloads\messengerfordesktop-setup_0544956837.exe”
C:\Users\USER\Downloads\messengerfordesktop-setup_0544956837.exe, Are you sure (Y/N)? Y
Access is denied.

That example “My dumps”
Thanks helped me flush my dump :v

OMG! After searching for eons finding a way to delete some empty folders that apparently were an issue for windows I finally found your explanation on how to use this command in the CMD prompt!
It worked! Hallelujah! This old lady finally now knows how to remove folders that are more headstrong then myself! Thank you!

how to copy copy specific folder like
c:\user\admin\desktop (i want to compeletely copy desktop file not thoose file which is inside the desktop)
i use this cmd
xcopy c:\user\admin\desktop e:\data
(but not copy desktop. thoose file are coppied which is inside the desktop folder.)

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

Jump Right In:

Deleting Folders / Directories Using CMD.

Deleting Files Using CMD.

Creating a dummy file with a specific size.

Delete Many Files Or Folders At Once.

Delete Files Or Folders From Any Directory.

What We’ll Learn:

Welcome!
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!

To delete a file or folder using the command prompt we must first navigate to the location of our file.

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

To view all the files in this directory use the “Dir” command, which stands for directory.

Every file in this directory will be displayed at once.

If the file or directory you want to delete is located at your desktop for example use the “Cd” command to change the command prompts directory.

Simply type “Cd” followed by the folder you want to navigate into within quotes.

You will at once navigate into the desktop directory and 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:

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.

Deleting Folders / Directories Using CMD​

To delete a folder use the “Rmdir” command, which stands for “Remove Directory”.

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

You might be wondering why we surrounded the name of our folder in quotes. The quotes tell the command line 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.

Читайте также:  Twonky server для linux

Rmdir” without any parameters only removes folders that are empty, to delete a folder along with the files or folders within it you need to use the /S parameter.
The command would look like this:

After entering the command the command line 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 with administration privileges, the wrong command can very easily break your computer.

Deleting Files Using CMD​

The command for deleting files using the cmd is “Del“. Unlike “ Rmdir “, “ Del “can only delete files. Using “ Del ” to delete a folder will constitute in an error .

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

Your file should be immediately deleted.

Once again if you file is not located in the users folder 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 administrator command prompt can very easily break your computer.
To delete more than one file at once simply enter all the names of your files one after the other.

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.

You can delete every file that begins with a set of characters by using a wildcard.
Wildcards are special symbols that take the place of characters or words.
The most commonly used wildcard is the asterix.

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

Every file that begins with the word “File” will be deleted.
To delete a set of folders instead, simply replace the Del command with Rmdir.

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.

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

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

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:

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

Summary:

  • 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.

Оцените статью