This question's answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions.
I want to delete a folder that contains thousands of files and folders. If I use Windows Explorer to delete the folder it can take 10-15 minutes (not always, but often). Is there a faster way in Windows to delete folders?
Other details:
I don't care about the recycle bin.
It's an NTFS drive.
The worst way is to send to Recycle Bin: you still need to delete them. Next worst is shift+delete with Windows Explorer: it wastes loads of time checking the contents before starting deleting anything.
Next best is to use rmdir /s/q foldername from the command line. del /f/s/q foldername is good too, but it leaves behind the directory structure.
The best I've found is a two line batch file with a first pass to delete files and outputs to nul to avoid the overhead of writing to screen for every singe file. A second pass then cleans up the remaining directory structure:
del /f/s/q foldername > nul
rmdir /s/q foldername
This is nearly three times faster than a single rmdir, based on time tests with a Windows XP encrypted disk, deleting ~30GB/1,000,000 files/15,000 folders: rmdir takes ~2.5 hours, del+rmdir takes ~53 minutes. More info at Super User.
This is a regular task for me, so I usually move the stuff I need to delete to C:\stufftodelete and have those del+rmdir commands in a deletestuff.bat batch file. This is scheduled to run at night, but sometimes I need to run it during the day so the quicker the better.
Technet documentation for del command can be found here. Additional info on the parameters used above:
/f - Force (i.e. delete files even if they're read only)
/s - Recursive / Include Subfolders (this definition from SS64, as technet simply states "specified files", which isn't helpful).
/q - Quiet (i.e. do not prompt user for confirmation)
Documentation for rmdir here. Parameters are:
/s - Recursive (i.e. same as del's /s parameter)
/q - Quiet (i.e. same as del's /q parameter)
Using Windows Command Prompt:
rmdir /s /q folder
Using Powershell:
powershell -Command "Remove-Item -LiteralPath 'folder' -Force -Recurse"
Note that in more cases del and rmdir wil leave you with leftover files, where Powershell manages to delete the files.
use fastcopy, a free tool.
it has a delete option that is a lot faster then the way windows deletes files.
use the command prompt, as suggested. I figured out why explorer is so slow a while ago, it gives you an estimate of how long it will take to delete the files/folders. To do this, it has to scan the number of items and the size. This takes ages, hence the ridiculous wait with large folders.
Also, explorer will stop if there is a particular problem with a file,
and to delete a lot of folders, you could also create a batch file with the command spdenne posted.
1) make a text file that has the following contents replacing the folder names in quotes with your folder names:
rmdir /s /q "My Apps"
rmdir /s /q "My Documents"
rmdir /s /q "My Pictures"
rmdir /s /q "My Work Files"
2) save the batch file with a .bat extension (for example deletefiles.bat)
3) open a command prompt (Start > Run > Cmd) and execute the batch file. you can do this like so from the command prompt (substituting X for your drive letter):
X:
deletefiles.bat
Try Shift + Delete. Did 24.000 files in 2 minutes for me.
Related
Probably there is a better approach to fix what I am trying to do. I have a folder with pictures that I want to copy to another folder renaming them.
Basically, I have a list of all the 80K files of the file name they have, and what is the new name that they should have. There is no fixed pattern to rename the files. What I’ve been doing is using Excel to find the path and current file name and then renaming the files checking the new file name in a SQL database.
Basically, for every file I form a XCOPY line then I paste them on powershell.
echo F|xcopy /s /q /y /f "file path" "renamed file path"
My problem is that for some reason powershell stops processing the xcopy lines after approximately 4K files. I already tried running this as a BAT with these lines for each file.
xcopy /s /q /y /f "file path" "renamed file path *" with an asterisk at end to avoid the question if it’s a file or a folder. But it stops processing after 2K files.
I know that robocopy is better than xcopy but I need to rename each file, and there is not a clear pattern in the renaming, I don’t know how to do a robocopy each file and then rename each file, but that should be even worse no?
Also, the server has a good SSD and its only processing 1 xcopy line per each second, should be a lot faster. The .jpg files are small (˜200Kb).
Any ideas are appreciated.
Regards,
Tiago
I'm using Windows 10 and need to update a batch file to clear the contents of folder at "C:\Users\myUserName\AppData\Local\Microsoft\Windows\INetCache". This is the folder that holds cache for Internet Explorer.
I would have thought the command was simply as follows:
DEL /S /F /Q C:\Users\myUserName\AppData\Local\Microsoft\Windows\INetCache\*
This command executes without issue, but when I look at the contents of the folder via Windows Explorer, it still has stuff in it. I say "stuff" because while it looks like a bunch of files, they don't behave like typical files. For instance, I cannot see these files when when I use "dir" on the command prompt no matter which flags I utilize. And when I examine the properties of these files, there is barely any information associated with them.
Why isn't my DEL command clearing out these files?
Screenshot of "files" still present in my INetCache folder
Screenshot of the properties of one of these files
I found that using the "rmdir" command instead of the "del" command resolved my issue.
rmdir "C:\Users\myUserName\AppData\Local\Microsoft\Windows\INetCache" /s /q
open txt and save .bat file
DEL /S /F /Q C:\Users\%username%\AppData\Local\Microsoft\Windows\INetCache\*
pause
I want to write a batch file to cleanup my Downloads folder by deleting everything in it Except Files and Folders that were created today.
Thanks.
If you are using modern Windows, recommend you use forfiles,
Folder can still messy. Do you want to do it based on the timestamp of the directory itself? Do you want to process recursively through all folders, deleting files based on date and then delete the folder if it empty after deleting the files of given age. There are other reasonable interpretations of your question as well. Personally, I use a python script so I can make the file cleanup do exactly what I want. This may also be why Uriil suggested PowerShell.
Arguably, Windows Services for Unix downloadable from Microsoft would be considered fair game (allowing the find command mentioned by Johnride). If you use this, make sure Johnride suggestion matches your actual intent. For the find command, using the option -print instead of -exec is great for debugging
If you can use forfiles, this article may give what you want. I taking the liberty of pasting in the batch file solution using forfiles from the article.
#echo off
:: set folder path
set dump_path=c:\shares\dump
:: set min age of files and folders to delete
set max_days=1
:: remove files from %dump_path%
forfiles -p %dump_path% -m *.* -d -%max_days% -c "cmd /c del /q #path"
:: remove sub directories from %dump_path%
forfiles -p %dump_path% -d -%max_days% -c "cmd /c IF #isdir == TRUE rd /S /Q #path"
After a backup every file on a disk looks like filename_1.jpg
I am using del *_1.* to delete the file.s But can I use the command in D:\ to work down each folder either?
At present I use del *_1.* then cd .. the cd into the next dir, and so on.
Be very, very careful with this command. One false move and you can do a lot of damage...
First try
dir /b /s "d:\*_1.*"
which should show you a list of target files to check. If you like, you can use "d:\somedirectory\*_1.*" to start at some subdirectory.
Once you're satisfied with your list, the command you want is
del /s "d:\*_1.*"
Which I usually invoke by up-arrowing to return the previous command and editing the DIR /B to DEL to make sure that I don't change the filemask.
But as I say - use with extreme caution! The /s is the magic - it means 'and in subdirectories'
I wish to delete a lot of files on windows quickly as possible.
Got any suggestions on how to do it (in batch script, windows command or ant script etc.)?
I was thinking of the following directions:
Parallel deletion. It apperats that when I delete a bunch of files it takes longer than deleting groups of these files parallely.
Any (quick!) way to make these files on creation time to "sit" closely on the disk?
Any optimizations in deletion, given that the deletion is permanat?
Any lazy mechanism windows has. That is, it doesn't really delete the files at that moment, but creates the effect that it did (you won't see it on the cmd.exe dir command or on the gui, and you could create a new file with a name that used to exist etc.) and windows will continue the real deletion in the background.
Any input will be extremely helpfull,
Thank you.
I find that the command line tends to be faster with file operations. For example, to delete C:\Parent\Folder\OldFolder, open the Command Prompt and type:
CD "C:\Parent\Folder"
Attrib -R -S -H "OldFolder\*.*" /S /D /L
RD /S /Q "OldFolder"
You could try using the commmand line as Hand-E-Food said. You can use these commands to delete files and remove folders.
del /f /s /q
rd /s /q
Or use wildcards to wipe all files out from a directory:
del C:\filestodel\*.* /f /s /q