I need to create a batch file to copy some files. I have several files on a folder, having all of them a date as part of the filename, and only some of them have the current day date. i.e.:
backupone_2013-11-19.zip
backupone_2013-11-18.zip
backupone_2013-11-17.zip
backuptwo_2013-11-19.zip
backuptwo_2013-11-18.zip
backuptwo_2013-11-17.zip
I need to duplicate (copy in the same folder) only those files named with current date, naming the new files with the format (left 8 chars)&"last".zip
Using the same example, it should be:
backupone_2013-11-19.zip
backupone_2013-11-18.zip
backupone_2013-11-17.zip
backuptwo_2013-11-19.zip
backuptwo_2013-11-18.zip
backuptwo_2013-11-17.zip
backupone_last.zip
backuptwo_last.zip
where the "last" files are related to the current day
I know how to select the files to copy (those with today´s date), but I can extract their left filename letters to copy them as new files
Update:
I've been trying the following script:
These are the files
C:\temp\test>dir *.zip /B
backupone__2013-11-18__16-18-53(Completo).zip
backupone__2013-11-19__16-18-53(Completo).zip
backupthree__2013-11-18__16-18-53(Completo).zip
backupthree__2013-11-19__16-18-53(Completo).zip
backuptwo__2013-11-19__16-18-53(Completo).zip
this is the full script
@echo off
cls
rem ----------------------------------------------
REM #### Today´s date
rem DATE FORMAT YYYY-MM-DD
SET fechahoy=%date:~6,4%-%date:~3,2%-%date:~0,2%
echo -----------------Debug: fechahoy
echo %fechahoy%
echo.
REM #### directory where the files are saved
cd "C:\temp\test\"
echo -----------------Debug: dir
echo "*%fechahoy%*".zip
echo.
dir /B /A-D "*%fechahoy%*".zip
echo.
for /f "Tokens=1 delims=_" %%a in ("C:\temp\test\*%fechahoy%*.zip") do (
echo %%a_Last.zip
)
and here is the result:
-----------------Debug: fechahoy
2013-11-19
-----------------Debug: dir
"*2013-11-19*".zip
backupone__2013-11-19__16-18-53(Completo).zip
backupthree__2013-11-19__16-18-53(Completo).zip
backuptwo__2013-11-19__16-18-53(Completo).zip
C:\temp\test\*2013-11-19*.zip_Last.zip
Any idea?
Any help will be greatly appreciated