DosTips.com

A Forum all about DOS Batch
It is currently 28 Aug 2016 16:20

All times are UTC-06:00




Post new topic  Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 10 May 2012 04:37 
Offline

Joined: 10 May 2012 01:29
Posts: 5
i hv a folder call c:\data\ in which every day (12 am to 1 am) one files generate with file name 20120510.csv (yyyymmdd.csv) each file updated till (12 am morning. after that i rename file with a code like 416 as 416_20120510.csv and then transfer over network . My problem is there are many files in folder like 20120509.csv etc... My problem is not rename today's file created except this all files are rename with a code 416_yyyymmdd.csv


Kindly help me


Top
   
PostPosted: 10 May 2012 05:31 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5907
This will rename the *most recent* .csv file in the folder.

Code:
@echo off
for /f "delims=" %%a in ('dir *.csv /b /od') do set "file=%%a"
ren "%file%" "416_%file%"


Top
   
PostPosted: 10 May 2012 05:35 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5907
I think misunderstood your English.

Is there one file created with todays date that you do not want to have renamed?

Or are there more files with todays date?


Top
   
PostPosted: 11 May 2012 00:26 
Offline

Joined: 10 May 2012 01:29
Posts: 5
Yes i don't want to rename file created or generated today


Top
   
PostPosted: 11 May 2012 00:29 
Offline

Joined: 10 May 2012 01:29
Posts: 5
i.e in folder there are many files like including today file (i.e 20120511.csv and old dated file like 20120510.csv, 20120509.csv etc...) so i want to rename excluding today file (i.e 20120511.csv)


Top
   
PostPosted: 11 May 2012 01:07 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5907
It's easy to do without testing for date if there is only one file every day.

This will skip the newest file in the folder and rename the rest.

Quote:
@echo off
for /f "skip=1 delims=" %%a in ('dir *.csv /a-d /b /o:-d') do ren "%%a" "416_%%a"


Top
   
PostPosted: 11 May 2012 02:07 
Offline

Joined: 10 May 2012 01:29
Posts: 5
Thanks but my all files are in c:\data\ so where i have to mention the directory path in batch file


Top
   
PostPosted: 11 May 2012 06:17 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3169
priya171 wrote:
Thanks but my all files are in c:\data\ so where i have to mention the directory path in batch file

If you put the batch file in C:\data you don't have to put the path in the batch file.

If you really want to put it in there then add it to the DIR command.


Top
   
PostPosted: 11 May 2012 06:35 
Offline

Joined: 10 May 2012 01:29
Posts: 5
Thank you very much


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 9 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: misol101, Yahoo [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited