Computing.Net > Forums > Disk Operating System > Deleting Oldest Directory

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.

Deleting Oldest Directory

Reply to Message Icon

Name: toyotaco01
Date: June 9, 2003 at 21:04:57 Pacific
OS: XP Pro
CPU/Ram: 1.4 ghz 612mb
Comment:

I have a simple batch program that creates a directory named MMDDYYYY and makes a backup of several files that it puts in that directory. Since I am running out of HD space, I wanted to add a section of code to the beginning of the batch file so that it would delete the oldest directory. (i.e so if the directories were 05252003 05302003
and 06062003 , it would delete the directory named 05252003 ) I'm really new to batch files (and DOS really). Thanks in advance for your help guys



Sponsored Link
Ads by Google

Response Number 1
Name: Johan_af
Date: June 9, 2003 at 23:13:14 Pacific
Reply:

If you know about batch files, im sure you know dos commands. To delete files in dos, you use the DEL command. Try putting this into the start:

DEL x:\05252003\*.*

this will delete the files in the directory But the name of the directory will still be there when you types dir or wathever.

Sorry about my bad english!

NOTE: X: is the drive letter. Very often C:


0

Response Number 2
Name: toyotaco01
Date: June 10, 2003 at 15:44:00 Pacific
Reply:

Thanks for the reply, but thats not exactly what I was looking for. I was hoping to figure out how to scan through all of the directories to figure out which file was the oldest (i.e. smallest number in the format MMDDYYYY)


0

Response Number 3
Name: Scott
Date: July 1, 2003 at 09:03:03 Pacific
Reply:

The code below will do what you need (it will only run on NT, 2000, XP):

The code assumes that your MMDDYYY directories are in c:\Backups.

In case the code wraps lines, it should be in two lines: second line starts with "rd"
Also, there are spaces between the /f and the %%i, and between each of the /b, /ad, /o-d.

for /f %%i in ('dir c:\Backups /b /ad /o-d') do set OldestDir=%%i
rd /s /q c:\Backups\%OldestDir%

Enjoy!


0

Response Number 4
Name: toyotaco01
Date: July 1, 2003 at 16:56:58 Pacific
Reply:

Thanks for the help, it worked great


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 Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Deleting Oldest Directory

How do you delete a directory in dos? www.computing.net/answers/dos/how-do-you-delete-a-directory-in-dos/9742.html

Unable to delete a directory www.computing.net/answers/dos/unable-to-delete-a-directory/12087.html

How to delete the c:\Windows directory www.computing.net/answers/dos/how-to-delete-the-cwindows-directory/5087.html