Computing.Net > Forums > Programming > .bat script for latest file

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.

.bat script for latest file

Reply to Message Icon

Name: Ravi_varma
Date: June 12, 2008 at 02:11:24 Pacific
OS: xp
CPU/Ram: amd
Product: 2004
Comment:

i have .csv files with timestamps in a folder lke below.

20080302112305.csv
20080302123005.csv
20080302131207.csv
20080302172309.csv

I need to keep only the latest file and delete rest of the files in that folder...in this case i want to keep only
20080302172309.csv file and delete remaing.

Please suggest how can i do it in batch scripting which needs to be executed in windows

thx,
ravi



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: June 12, 2008 at 02:54:13 Pacific
Reply:

@echo off
setlocal enabledelayedexpansion
set latest_skipped=
for /f "delims=" %%a in ('dir /b /a-d /o-n 20*.csv') do (
if defined latest_skipped (
del %%a
) else (
set latest_skipped=1
)
)


0

Response Number 2
Name: Mechanix2Go
Date: June 12, 2008 at 03:01:43 Pacific
Reply:

not tested

::== keeplast

@echo off
setLocal EnableDelayedExpansion

for /f "skip=1 tokens=* delims= " %%a in ('dir/b/o-n *.csv') do (
del %%a
)


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

M2


0

Response Number 3
Name: klint
Date: June 12, 2008 at 03:53:50 Pacific
Reply:

Good one, M2, I forgot about the usefulness of the "skip" keyword.


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: .bat script for latest file

File rename in CMD or Bat script www.computing.net/answers/programming/file-rename-in-cmd-or-bat-script/14672.html

Need VB or .bat script for Textpad. www.computing.net/answers/programming/need-vb-or-bat-script-for-textpad/17282.html

script for sending file to remote p www.computing.net/answers/programming/script-for-sending-file-to-remote-p/15821.html