Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append date to directory path in xcopy

I do have a xcopy statement in bat file.. would you please help me to append today's date to one of directories in destination xcopy /S /E /I %sourceFolder% "C:\Shared\copy\%destinationFolder%"

today date is 06072013 so I want my destination look like below

C:\Shared\copy-today's date........

Thanks

like image 209
user2434611 Avatar asked Nov 16 '25 10:11

user2434611


2 Answers

This is method of getting a date stamp that doesn't depend on the regional settings. Wmic is available in Windows XP Pro and higher.

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
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 stamp=%YYYY%-%MM%-%DD%

md "C:\Shared\copy-%stamp%"
xcopy here...
like image 113
foxidrive Avatar answered Nov 18 '25 22:11

foxidrive


xcopy /S /E /I %sourceFolder% "C:\Shared\copy-%date:/=%\%destinationFolder%"
like image 39
Aacini Avatar answered Nov 19 '25 00:11

Aacini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!