Computing.Net > Forums > Programming > batch script to pick thelatest 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.

batch script to pick thelatest file

Reply to Message Icon

Name: shalini.das
Date: April 24, 2008 at 11:40:23 Pacific
OS: windows xp
CPU/Ram: Pentium Dual Core / 2 Gb
Product: Shuttle
Comment:

HI All,
I am new to batch scripting and this is my first script pls help me out.

I have to right a batch script, which has to pick the latest file in my directory in which file name are as below,
filename_2007-12-23.txt
filename_2007-12-30.txt
filename_2008-01-06.txt
after picking the latest file it has to rename the latest file as below.
filename_20071223.txt
filename_20071230.txt
filename_20080106.txt

Please suggest me how i can do this.

Best Regards,
Shalini



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 24, 2008 at 20:45:46 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d/o-d c:\files\*.txt') do (
set latest=%%a & goto :done
)
:done
echo latest is !latest!


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

M2


0

Response Number 2
Name: shalini.das
Date: April 25, 2008 at 02:25:26 Pacific
Reply:

HI,

Thanks a lot for the script, i tried it on ms- dos .bat file, but it was not picking and renaming any file.

Pls tell me how can i do this.

Best regards,
Shalini


0

Response Number 3
Name: Mechanix2Go
Date: April 25, 2008 at 03:51:10 Pacific
Reply:

I though we were talking about XP. It will take much more work in DOS. What version are you using?


=====================================
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 script to pick thelatest file

Batch Script To FTP a file www.computing.net/answers/programming/batch-script-to-ftp-a-file/17008.html

Script to move/delete files www.computing.net/answers/programming/script-to-movedelete-files/14985.html

batch script to upload to ftp www.computing.net/answers/programming/batch-script-to-upload-to-ftp/16987.html