Found the same question here.. I am trying to use the code but for my data. I am in no way a programmer.. I can take almost any code and make it work for me however.
How to code a batch file to copy and rename the most recently dated file?
Here is my
@echo on
setLocal DisableDelayedExpansion
pushd N:\
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%G in ('dir/b/od') do (set newest=%%G)
copy %newest% G:\Server_Files\AMI_DATA\TEXT_FILES\NewFile.csv
PAUSE
POPD
And the results...
C:\Documents and Settings\belcherj\Desktop\AMI_BATCH>setLocal DisableDelayedExpa
nsion
C:\Documents and Settings\belcherj\Desktop\AMI_BATCH>pushd N:\
N:\>setLocal EnableDelayedExpansion
N:\>for /F "tokens=* delims= " %G in ('dir/b/od') do (set newest=%G )
N:\>(set newest=System Blink Count__2012-06-27 01_00_46.csv )
N:\>(set newest=System Blink Count__2012-06-28 01_00_32.csv )
N:\>(set newest=System Blink Count__2012-06-29 01_00_33.csv )
N:\>(set newest=System Blink Count__2012-06-30 01_00_42.csv )
N:\>(set newest=System Blink Count__2012-07-01 01_00_32.csv )
N:\>(set newest=System Blink Count__2012-07-02 01_00_31.csv )
N:\>(set newest=System Blink Count__2012-07-03 01_00_29.csv )
N:\>(set newest=System Blink Count__2012-07-04 01_00_39.csv )
N:\>(set newest=System Blink Count__2012-07-05 01_00_34.csv )
N:\>(set newest=System Blink Count__2012-07-06 01_00_31.csv )
N:\>(set newest=System Blink Count__2012-07-07 01_00_32.csv )
N:\>(set newest=System Blink Count__2012-07-08 01_00_30.csv )
N:\>(set newest=System Blink Count__2012-07-09 01_00_40.csv )
N:\>(set newest=System Blink Count__2012-07-10 01_00_29.csv )
N:\>(set newest=System Blink Count__2012-07-11 01_00_44.csv )
N:\>(set newest=System Blink Count__2012-07-12 01_00_34.csv )
N:\>copy System Blink Count__2012-07-12 01_00_34.csv G:\Server_Files\AMI_DATA\TE
XT_FILES\NewFile.csv
The system cannot find the file specified.
N:\>PAUSE
Press any key to continue . . .
I think it has something to do with the spaces in the file names.. I tried some other code i found and it gave the same results. Im close just need a little push. Thanks for you time and help.