Is there a way to delete all empty sub-directories below a given directory from a batch file?
Or is it possible to recursively copy a directory, but excluding any empty directories?
Is there a way to delete all empty sub-directories below a given directory from a batch file?
Or is it possible to recursively copy a directory, but excluding any empty directories?
You really have two questions:
1. Is there a way to delete all empty sub-directories below a given directory from a batch file?
Yes. This one-line DOS batch file works for me. You can pass in an argument for a pattern / root or it will use the current directory.
The reason I use 'dir|sort' is for performance (both 'dir' and 'sort' are fairly fast). It avoids the recursive batch function solution used in one of the other answers which is perfectly valid but can be infuriatingly slow :-(
2. Or is it possible to recursively copy a directory, but excluding any empty directories?
There are a number of ways to do this listed in other answers.
To copy ignoring empty dirs you can use one of:
xcopy's /s will ignore blank folder when copying
This batch file does the trick just fine from any path, in my case I use Windows Environment variable IWAY61 :
Call with:
rmemptydirs.cmd "c:\root dir to delete empty folders in"