I need to delete all empty folders from my application folder using windows command prompt?
How can I create a bat file like that?
Please help me.
I need to delete all empty folders from my application folder using windows command prompt?
How can I create a bat file like that?
Please help me.
from the command line: for /R /D %1 in (*) do rd "%1"
in a batch file for /R /D %%1 in (*) do rd "%%1"
I don't know if it's documented as such, but it works in W2K, XP, and Win 7. And I don't know if it will always work, but it won't ever delete files by accident.
Adding to corroded answer from the same referenced page is a PowerShell version http://blogs.msdn.com/b/oldnewthing/archive/2008/04/17/8399914.aspx#8408736
Get-ChildItem -Recurse . | where { $_.PSISContainer -and @( $_ | Get-ChildItem ).Count -eq 0 } | Remove-Item
or, more tersely,
gci -R . | where { $_.PSISContainer -and @( $_ | gci ).Count -eq 0 } | ri
credit goes to the posting author
You can use ROBOCOPY. It is very simple and can also be used to delete empty folders inside large hierarchy.
Here both source and destination are
folder1
, as you only need to delete empty folders, instead of moving other(required) files to different folder./S
option is to skip copying(moving - in the above case) empty folders. It is also faster as the files are moved inside the same drive.Install any UNIX interpreter for windows (Cygwin or Git Bash) and run the cmd:
(not really using the windows cmd prompt but it's easy and took few seconds to run)
This is a hybird of the above. It removes ALL files older than X days and removes any empty folders for the given path. To use simply set the days, folderpath and drive