Computing.Net > Forums > Programming > Batch file to delete empty folders

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to delete empty folders

Reply to Message Icon

Name: malloy
Date: November 30, 2007 at 15:29:53 Pacific
OS: win xp sp2
CPU/Ram: Intel Xeon 2.80 GHz 3 GB
Product: Dell
Comment:

We have a directory c:\temp that act as storage for a directory monitor for printing before it moves files along. Within c:\temp a unique folder name is created along with a inbound and outbound folder within that for each print job that is sent. After processing the print job it leaves all these folders. I need a batch file that will delete all the folders and subfolders in c:\temp as long as they are empty of files. We are piling up thousands of these folders a day and deleting them manually is becoming tiresome.




Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: November 30, 2007 at 18:13:52 Pacific
Reply:

The following relies on the fact that rd /q will only delete an empty directory:

pushd c:\temp
for /d %%d in (*) do rd /q %%d
popd


0

Response Number 2
Name: Mechanix2Go
Date: November 30, 2007 at 18:25:25 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

dir/b/s/ad c:\temp | sort /r > sdlist

for /f "tokens=* delims= " %%d in (sdlist) do (
rd %%d 2>nul
)



=====================================
If at first you don't succeed, you're about average.

M2



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file to delete empty folders

Batch file to delete unknown folder www.computing.net/answers/programming/batch-file-to-delete-unknown-folder/19956.html

Batch File To Delete Line www.computing.net/answers/programming/batch-file-to-delete-line/15539.html

Batch file to delete files in a dir www.computing.net/answers/programming/batch-file-to-delete-files-in-a-dir/14599.html