How to find all empty directories in Windows? For Unix there exists find. So there is an out of the box solution. What is the best solution using windows?
Asked
Active
Viewed 441 times
1 Answers
1
I found several solutions so far:
- Use Powershell to find empty directories
- Install Cygwin or Gnu Findtools and follow the unix approach.
- Use Python or some other script language, e.g. Perl
This Powershell snippet below will search through C:\whatever and return the empty subdirectories
$a = Get-ChildItem C:\whatever -recurse | Where-Object {$_.PSIsContainer -eq $True}
$a | Where-Object {$_.GetFiles().Count -eq 0} | Select-Object FullName
This python code below will list all empty subdirectories
import os;
folder = r"C:\whatever";
for path, dirs, files in os.walk(folder):
if (dirs == files): print path
-
2I would say Powershell approach should be the one to be used by the OP. Do you imagine using a Unix abstraction layer/emulator if there's a Windows-based solution? ;) – Matías Fidemraizer Sep 02 '13 at 10:25
-
Yes, I am working on both windows and unix and thus prefer solutions that work with both. Actually in the case where this issue came up I preferred the python solution. I just added the powershell way for completeness. I will sort it up though. – Udo Klein Sep 02 '13 at 10:28
-
I didn't see that's your own answer... :P Well, it's up to you. – Matías Fidemraizer Sep 02 '13 at 10:44