: need to copy \\Myserverdir\File.txt to C:\mydir\Test_(date_creation).txt
setlocal
:: the following are what I used to test - change to yours!
set folder=\\SynDS214\share
set file=File.txt
set target=D:\Backup
:: get the file's date as dd/mm/yyyy
for /f "tokens=1" %%a in ('dir "%folder%\%file%" ^| find /i "%file%"') do set filedate=%%a
:: change the date to yyyymmdd
set date_created=%filedate:~6,4%%filedate:~3,2%%filedate=~0,2%
:: perform the copy, if the file is not present in the target
if not exist "%target%\Test_(%date_created%).txt" ^
copy "%folder%\%file%" "%target%\Test_(%date_created%).txt"
:: check on the copied file
dir "%target%\Test_(%date_created%).txt"
endlocal
why the conversion od date return 201607 instead 20160712
setlocal
:: the following are what I used to test - change to yours!
set folder=\\SynDS214\share
set file=File.txt
set target=D:\Backup
:: get the file's date as dd/mm/yyyy
for /f "tokens=1" %%a in ('dir "%folder%\%file%" ^| find /i "%file%"') do set filedate=%%a
:: change the date to yyyymmdd
set date_created=%filedate:~6,4%%filedate:~3,2%%filedate=~0,2%
:: perform the copy, if the file is not present in the target
if not exist "%target%\Test_(%date_created%).txt" ^
copy "%folder%\%file%" "%target%\Test_(%date_created%).txt"
:: check on the copied file
dir "%target%\Test_(%date_created%).txt"
endlocal
why the conversion od date return 201607 instead 20160712