Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have to write a batch file to delete the oldest file in a folder, but i don't know how to get the name of the oldest file.

I can sort files with DIR, DIR /B /O:D /T:C but this is a list and i need the first file (since it sorts the oldest first) in that list.

How can I do it?

Thanks

share|improve this question

3 Answers 3

up vote 1 down vote accepted

That dredged up some painful memories! I found this one:

http://www.chebucto.ns.ca/~ak621/DOS/Bat-Adv3.html#OLD

I won't cut and paste the script as there is a really nice write up there.

share|improve this answer

I think this should be possible with the forfiles command. Technet link. But it is not included in WinXP. There are however "Resource Kits" from Microsoft which include several Tools, forfiles is one of them. Try to google the "Windows 2000 Resource Kit", it includes forfiles IIRC.

share|improve this answer

would be sooo easy with gnu userspace apps for windows. :)

You might want to check it out if you have a possibility to install tools on the machine in question.

http://getgnuwin32.sourceforge.net/

Sourceforge currently has some guru meditation issues, but hope the link works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.