Page 1 of 1

rename all files excep today files and transfer over network

Posted: 10 May 2012 04:37
by priya171
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

Re: rename all files excep today files and transfer over net

Posted: 10 May 2012 05:31
by foxidrive
This will rename the *most recent* .csv file in the folder.

Code: Select all

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

Re: rename all files excep today files and transfer over net

Posted: 10 May 2012 05:35
by foxidrive
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?

Re: rename all files excep today files and transfer over net

Posted: 11 May 2012 00:26
by priya171
Yes i don't want to rename file created or generated today

Re: rename all files excep today files and transfer over net

Posted: 11 May 2012 00:29
by priya171
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)

Re: rename all files excep today files and transfer over net

Posted: 11 May 2012 01:07
by foxidrive
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.

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

Re: rename all files excep today files and transfer over net

Posted: 11 May 2012 02:07
by priya171
Thanks but my all files are in c:\data\ so where i have to mention the directory path in batch file

Re: rename all files excep today files and transfer over net

Posted: 11 May 2012 06:17
by Squashman
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.

Re: rename all files excep today files and transfer over net

Posted: 11 May 2012 06:35
by priya171
Thank you very much