- Rmdir : Delete directory from command line
- Delete folder from CMD
- How to delete a non empty folder
- Force delete a folder without confirmation
- Deleting directory with white spaces in the name
- Delete contents of a directory but keep the directory
- Errors
- How to remove all files from a directory?
- 9 Answers 9
- Delete files or folder recursively on Windows CMD
- 12 Answers 12
- Use the Windows rmdir command
- cmd Delete Folder – How to Remove Files and Folders in Windows
- Kris Koishigawa
- How to open Command Prompt
- How to delete files with the del command
- How to force delete files with the del command
- How to delete folders with the rmdir command
- How to use the /s flag with rmdir
- Kris Koishigawa
Rmdir : Delete directory from command line
Do you want to delete a directory from Windows command prompt(CMD)? This post explains how to use the command rmdir to delete folders and their contents. You can also find examples for each use case of folder deletion – empty folders, non empty folders, folders with white spaced names etc.
Delete folder from CMD
Run the command rmdir on the folder.
How to delete a non empty folder
The simple rmdir does not work for folders having some content.
Use /s option to delete the folder contents along with the folder. This deletes all subfolders recursively.
Force delete a folder without confirmation
To force delete directory, without being asked for confirmation, we can use /Q switch.
We can also use ‘rd’ in place of ‘rmdir‘. Both names refer to the same command. This command works on Windows 2000, Windows XP, Server 2003, Vista, Windows 7 and 10.
Deleting directory with white spaces in the name
Rmdir can delete files with whitespaces in the name, you just need to wrap up the folder name in double quotes as shown in the below example.
Delete contents of a directory but keep the directory
The usecase here is to delete all the contents of the directory but keep the parent directory so that we do not need to create it again. rmdir /Q /S does not work here as it deletes the parent directory too. Rather the below commands should do the trick.
This works in 2 steps – the first command deletes all files, whereas the second one deletes all subdirectories.
Errors
To delete a directory, you should have appropriate access permissions on the directory. Otherwise rmdir throws ‘Access denied’ error.
Thanks dude..I was looking for command line way of deleting nonempty folders.. cheers.
Good old DOS….something tells me one day the world will be saved by a DOS operation. ; )
cannot delete… access is denied. am trying to delete a directory on a flash drive. cannot access permissions because explorer isn’t working. using win7
Note:
Don’t forget to leave a “space” in the command line..
rmdir /Q /S_“folder with spaces in the name” I meant “space”, ait’t “underscore”. And upper case of “S”. Good luck!
Hi
can you show me an example of command to delete this path in bat file.
C:\Program Files\Microsoft Office Communicator
am not able to do this . some error s
Is this in Windows 7/Vista?.
If so then you need to take ownership of the files. You can do that with below command from elevated administrator command prompt.
takeown /F «c:\Program Files\Microsoft Office Communicator» /R /A
then run the below command to delete this folder.
rmdir /S «c:\Program Files\Microsoft Office Communicator»
cd program files\microsoft office communicator
then enter press
rd /s “filename”
Then enter
I am getting the following error “The process cannot access the file because it is being us
ed by another process.” what should be the case now?
You should not have the Dir you want to delete open… Close it and then try the command again
Could you kindly post the command for deleting my folder which is at Drive G. Name of the folder is Recycler. Thanks
Thank you so much. I was trying to delete an entire directory of files, about 200k folders and files, and it kept throwing a warning “this folder is shared with other people”. No such warning with this command!
i followed your instructions but i’m getting error to delete a folder in cmd. ERROR = The system cannot find the the specified…
You should make “C:” your default Directory, tot do this type “cd.. && cd..” The type the command again but leave the “C:\” and just type the rest of the code.
It should look like this: C:>rmdir /Q /S Users\Owner\Songs\New
i have installed new win 8 n a back up of old win 8 is in c drive with a name windows old n its not being deleted by ANY means . i have tried this one as well but it says on all files access is denied
I tried the process many times but it says “access is denied”….
My entire path is “C:\program files\alwil software\avast5” . How should i delete this avast5 folder with all the folders inside it.
run cmd.exe as administrator
make sure avast service is not running
Every time I try it says the file cant be found
you’re really awesome. Googled a 1000 times just for this line
“C:\>rmdir /S nonemptydir
nonemptydir, Are you sure (Y/N)? y”
Thank you so much for your help. This changed my life.
Thank you so much for your help. This changed my life.
please attache more basic command for beginner person for my email
tnx
I need to do that, help me out
D:\abc\ has files and folders in it
but by using rd or rmdir
rmdir d:\abc\ /s /q will delete abc folder also but i don’t want this.
the asterisk stands for ‘anything’ in or below the named directory.
I want to delete subfolders of a folder older than 10 days.I am able to delete files but not folder
I wanted to know the bat file programm for deleting the contents (sub folders) of a folder on certain conditions. can anyone help.?
How to delete folders created programatically with timestamp attached at the end.
Like we do for files :
DEL comp*
Is there any command for folders:
RM com*
or
RMDIR com*
I’m wanting to delete the directory c:\windows.old I followed the instructions above I run CMD as admin, I typed in: takeown /F c:\windows.old /R /A And hit enter key. It did this part properly but Then I typed in: rmdir /Q /S c:\windows.old And after every entry it said Access denied. what is the command line/s i need to type to atlas delete the directory c:\windows.old ? (using windows 10)
I got the same problem…….
please someone help.
thank you .
i m so glad
I followed the instructions above I run CMD as admin, I typed in: takeown /F c:\windows.old /R /A And hit enter key. It did this part properly but Then I typed in: rmdir /Q /S c:\windows.old And after every entry it said Access denied. what is the command line/s i need to type to atlas delete the directory c:\windows.old ? (using windows 10.
Please somebody help………………………
takeown /f D:\OrganizationalUnit\Everyone /r /d y
icacls D:\OrganizationalUnit\Everyone /grant administrators:F /T
attrib -s -h -r D:\OrganizationalUnit\EVERYONE /s /d
forfiles /P D:\OrganizationalUnit\Everyone\ -S -M *.* /D -2 /C “cmd /c del /f /q @PATH”
forfiles /P D:\OrganizationalUnit\Everyone\ /M * /D -2 /C “cmd /c if @isdir==TRUE rmdir /S /Q @file”
Thank you very much! With these commands I could remove all “c:\Windows.old” files and directories.
Hello,
I have four folders and I want to keep two of them along with their contents and delete other two folders. How can I do that?
My Parent folder -> Folder 1 (file1.txt), Folder 2 (file2.txt), Folder 3 (file3.txt), Folder 4 (file4.txt).
Need to delete or remove 2 folders and keep 2 folder with their content.
Need command for this.
Any help will be appreciated.
Super Cool!! Deleted a stubborn non empty directory in no time. Thanks for this guide.
I have several folder: folder1, folder2, folder3
how to delete all “folder” with *
Note: This commands doest’n work:
RM folder*
or
RMDIR folder*
I want to thank you very much for the help on deleting these files. I ended up using the CMD method, but it worked perfectly. Again, thank you.
Thanks. After struggling for months and hunting the web, I was finally able to delete a folder using your advice “Deleting directory with white spaces in the name”
OMG! Thank you! Was trying to delete the remaining empty folders of an old eset nod, but couldn’t. This did the trick (hoping). I’m just wondering if its still in the background somewhere. T.hanks again
in programatically if any changes in the inner files or directory after delete the parent directory doesnot work
eg:
system(“rmdir /s/q \””d:/test/hari\””);——>it works
but after
system(“rmdir /s/q \””d:/test\””);—–>it doesn’t work
Thank you for these still useful tips.
That worked verywell. Thank You
I tried the command, but someone has created the directory repeatedly and now I can not removed the base directory. Help
E:\>rmdir /s /q thur2
thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Th
ur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur
2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\
Thur2\AC_FSQ
1.ZIP – The file name is too long.
thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Th
ur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur
2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\
Thur2\AC_HR1
1.ZIP – The file name is too long.
thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Th
ur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur
2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\
Thur2\AC_HR1
2.ZIP – The file name is too long.
The path thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2
\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\T
hur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thur2\Thu
r2\Thur2\Thur2\Thur2\AC_FSQ
How to remove all files from a directory?
The closest I’ve gotten is
but that doesn’t work for files that don’t have an extension.
9 Answers 9
Linux does not use extensions. It is up to the creator of the file to decide whether the name should have an extension. Linux looks at the first few bytes to figure out what kind of file it is dealing with.
To remove all non-hidden files* in a directory use:
However, this will show an error for each sub-directory, because in this mode it is only allowed to delete files.
To remove all non-hidden files and sub-directories (along with all of their contents) in a directory use:
* Hidden files and directories are those whose names start with . (dot) character, e.g.: .hidden-file or .hidden-directory/ . Note that, in Bash, if the dotglob option (which is off by default) is set, rm will act on hidden files too, because they will be included when * is expanded by the shell to provide the list of filename arguments.
To remove a folder with all its contents (including all interior folders):
To remove all the contents of the folder (including all interior folders) but not the folder itself:
or, if you want to make sure that hidden files/directories are also removed:
To remove all the «files» from inside a folder(not removing interior folders):
Warning: if you have spaces in your path, make sure to always use quotes.
is equivalent to 2 separate rm -rf calls:
To avoid this issue, you can use ‘ single-quotes ‘ (prevents all expansions, even of shell variables) or » double-quotes » (allows expansion of shell variables, but prevents other expansions):
- rm — stands for remove
- -f — stands for force which is helpful when you don’t want to be asked/prompted if you want to remove an archive, for example.
- -r — stands for recursive which means that you want to go recursively down every folder and remove everything.
Delete files or folder recursively on Windows CMD
How do I delete files or folders recursively on Windows from the command line?
I have found this solution where path we drive on the command line and run this command.
I have given an example with a .svn file extension folder:
12 Answers 12
The other answers didn’t work for me, but this did:
/q disables Yes/No prompting
/s means delete the file(s) from all subdirectories.
Please execute the following steps:
- Open the command prompt
- Change directory to the required path
Give the following command
You can use this in the bat script:
Now, just change c:\folder a to your folder’s location. Quotation is only needed when your folder name contains spaces.
ex. RMDIR «C:\tmp» /S
Note that you’ll be prompted if you’re really going to delete the «C:\tmp» folder. Combining it with /Q switch will remove the folder silently (ex. RMDIR «C:\tmp» /S /Q )
For file deletion, I wrote following simple batch file which deleted all .pdf’s recursively:
Even for the local directory we can use it as:
The same can be applied for directory deletion where we just need to change del with rmdir.
If you want to delete a specific extension recursively, use this:
You could also do:
The /p will prompt you for each found file, if you’re nervous about deleting something you shouldn’t.
Use the Windows rmdir command
That is, rmdir /S /Q C:\Temp
I’m also using the ones below for some years now, flawlessly.
Check out other options with: forfiles /?
Delete SQM/Telemetry in windows folder recursively
Delete windows TMP files recursively
Delete user TEMP files and folders recursively
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.
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.