|
Answer» Hi to hall. my first post...
CODE: [Select] : 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
really i nee, in other case, 2016-07-12Try /......Try /......
?yyyy/mm/ddGetting a stable date and time format is the most FAQ since MSDOS V1.0 The fact that MS still hasn't provided it in cmd.exe boggles my mind.
These give you a reliable date and time format.
Code: [Select]@echo off rem The four lines below will give you reliable YY DD MM YYYY HH MIN Sec MS variables in XP Pro and higher. for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%" set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" & set "MS=%dt:~15,3%" set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%" & set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%-%MS%" echo datestamp: "%datestamp%" echo timestamp: "%timestamp%" echo fullstamp: "%fullstamp%" pause
Code: [Select]@echo off for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "date-time=%dt:~0,4%-%dt:~4,2%-%dt:~6,2%_%dt:~8,2%-%dt:~10,2%-%dt:~12,2%" echo date-time: "%date-time%" pause
|