Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List all empty folders in a directory 1

Status
Not open for further replies.

JohnOB

Technical User
Oct 5, 2006
253
GB
Does anyone know how to list all empty folders in a directory (or see them ordered by size, so I could easily spot the empty ones)?

Tried all kinds of searches, and dos things but can't think of anything else.

Thanks

John

"Stupid isn't not knowing the answer, it's not asking the question
 
There are a few possibilities that I could think of using batch files and/or shell commands, but there are some potential pitfalls that might take some thorough thinking and testing. (My initial thought involve using a for loop, dir /a-d, and possibly %errorlevel% evaluation). A .vbs script would probably be more efficient in this case. However, before going through something that involved and thinking about it too much, I first must ask: How often will you do this? How complicated and large is the directory structure that you want to do this with?

The reason is, that if it's a reasonbly small directory structure, and this is a one time thing, you can use a simple xcopy and manual comparison. Temporarily make a 'destination' folder for comparision. Then use xcopy source destination /t. The /t switch will copy the directory structure, creating all folders except the empty ones. Manually compare the source & destination - the folders missing in the destination are empty in the source.
 
PS, there are many third party tools that will do this sort of thing for you quite well. Some are nice paid utilities with many additional features, some are fairly simple open source applications like
 
Folder Size for Windows 2.4
Was what I came up with too, but if you allow it to remain on the machine (by not uninstalling it) then there are reports of it slowing Explorer considerably.

When searching for zero sized folders (0 bits) you may run into the problem of Desktop.ini (a Hidden file) which is in lots of folders and is usually something like 180 bytes (180 bytes) depending on what is in the .ini file. This may make your searches for empty folders fail if you are using zero bites as the size to search for.

If these Folders are empty and not taking up space, other than an entry in the Master File Table, perhaps you are worrying about "nothing", sorry about the pun.
 
Thanks snah the xcopy /t switch sounds like the ideal solution. The directory is 14/8GB with 2,583 folders, though this would be a one off thing. My plan was to do as you suggest, then dir the list of folders from both directories into a spreadsheet, then use access to compare them.

However, unfortunately I cannot seem to get the xcopy /t command to work. I used MS dos to navigate to the directory that contains all the other directories, I created a folder called 'ds' then I typed xcopy ds /t, it looks like the script runs OK (well there are no errors) but I don't see any progress, and when I go to the directory it is empty. I wondered if this could be due to the number of folders, or possibly that this directory resides on a file server and I am using the dos command at my machine, accessing the server from dos via its mapped drive letter?

Your help is appreciated.

Regards,

John

PS Unfortunately with the kind of organisation I work for installing third party tools such as those listed is not really an option.






"Stupid isn't not knowing the answer, it's not asking the question
 
source and destination (full paths) are both required for the xcopy command. You'd be better off having the destination be somewhere other than the folder you're working with. Since it will only be directories, you can put it anywhere - like your desktop. Use quotation marks if the path contains a space.

xcopy "c:\somepath\some source folder" "%userprofile%\Desktop\destination folder" /t
 
Smah, that worked like a charm my thanks to you!!!

Regards,

John

"Stupid isn't not knowing the answer, it's not asking the question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top