rename all files excep today files and transfer over network

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
priya171
Posts: 5
Joined: 10 May 2012 01:29

rename all files excep today files and transfer over network

#1 Post by priya171 » 10 May 2012 04:37

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#2 Post by foxidrive » 10 May 2012 05:31

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%"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#3 Post by foxidrive » 10 May 2012 05:35

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?

priya171
Posts: 5
Joined: 10 May 2012 01:29

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

#4 Post by priya171 » 11 May 2012 00:26

Yes i don't want to rename file created or generated today

priya171
Posts: 5
Joined: 10 May 2012 01:29

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

#5 Post by priya171 » 11 May 2012 00:29

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)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#6 Post by foxidrive » 11 May 2012 01:07

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"

priya171
Posts: 5
Joined: 10 May 2012 01:29

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

#7 Post by priya171 » 11 May 2012 02:07

Thanks but my all files are in c:\data\ so where i have to mention the directory path in batch file

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

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

#8 Post by Squashman » 11 May 2012 06:17

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.

priya171
Posts: 5
Joined: 10 May 2012 01:29

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

#9 Post by priya171 » 11 May 2012 06:35

Thank you very much

Post Reply