Link to home
Start Free TrialLog in
Avatar of bctek
bctek

asked on

How to delete all empty folders?

I have thousands of empty folders on my hard drive that have accumulated over the years.  Is there a way to do a search and delete of all empty folders w/o having to buy any third party software?  Preferably a native way?  My OS is windows 2000 server.

thank you!
Avatar of pweegar
pweegar

Well, there probably is no real easy way w/o buying comerical software. HOWEVER, I DO recommend going to www.iolo.com and download a 100% FREE trial of system mechanic. IT WILL find all those empty files (there is a check box to do this).  Plus this software will fix your system registry, you can tweak setting, plus a lot more. Give it a try!
Do you really want to kill them all?
Are you absolutely sure that your programs will not require the presence of *ANY* of these folders?
Is your system backed up, and are you prepared to handle the repercussions of this action?

Are you looking to do this for an entire drive, or just a subdirectory on the server?

As pweegar noted, a system optimization  utility may be a good choice as well - if your server has accrued a lot of folders, it likely has many reg entries as well.  If empty directories are all you need removed, this task seems like it will be able to be easily scripted into a batch file. Please confirm your intentions.
ASKER CERTIFIED SOLUTION
Avatar of bmedward
bmedward

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please let me know if the 'for' command in Win2K does not support the "/D" and "/R" options. - I can only check back to Win2003 server :(.
BTW, that command will work from the command line. As a batch file, you would need to double each of the "%"'s.

for /D /R . %%a IN ( * ) DO rmdir /q "%%a"

Also note, this will only delete one level of empty directories. If you have multiple levels of nested directories that are otherwise empty, you will need to run this multiple times to remove the entire tree.
>> Please let me know if the 'for' command in Win2K does not support the "/D" and "/R" options. - I can only check back to Win2003 server :(.

hey bmedward -

the 'for' command didn't error out on my system and I'm running w2k here at the office. I copied exactly what you had listed for the command line prompt and it worked for me. I do believe the question has been answered, as asked.

All hail bmedward, the mighty dos programmer!! ~smiles~
Avatar of bctek

ASKER

the empty directories are all on the D drive, which is the data drive.  I am not worried about removing needed directories that Windows might use.  Yes, many empty directories are nested inside other ones.  Thousands of them.  im going to try your for command now.  thanks. :)
Avatar of bctek

ASKER

yay, works fabulous.  great script!  thank you.
empty directories around the world - BEWARE!!!