Delete last file added to a directory batch

Microsoft Windows 2003 server - 5 users
June 7, 2010 at 10:56:35
Specs: Windows XP
All,

I need to delete the last added file from a directory through command lines. I am new to batch files. Please help.

Thanks,

Suab


See More: Delete last file added to a directory batch

Report •


#1
June 7, 2010 at 14:16:24
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/o-d/tc') do (
del %%a
goto :eof
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
June 7, 2010 at 15:55:21
Thanks Mechanix2Go,

That worked perfectly as per my need..

Suab


Report •

#3
June 7, 2010 at 16:17:18
Hi Mechanix2Go,

May I know how to write and If statement to compare a set date against a system date. Actually I want to perform the above (last file deletion from a directory) on a set date everymonth.

Thanks in advance,

Suab


Report •

Related Solutions

#4
June 7, 2010 at 17:10:07
Post a few lines of a DIR like this:

08-06-10 05:09 1,078 PIPELINE.BAT
08-06-10 06:51 80 MYFILE.BAK
08-06-10 06:52 87 MYFILE

and the output of:

echo %DATE%


=====================================
Helping others achieve escape felicity

M2


Report •

Ask Question