How to use Robocopy to copy files with TimeStamp in command line
I tried this lines and it works. it created the directory in such a way Fri 06_26_2015
for /f "tokens=1* delims=" %%a in ('date /T') do set datestr=%%a
md F:\Builds\"%date:/=_%"
ROBOCOPY "K:\Builds" "F:\Builds\%date:/=_%" /E /COPY:DAT /DCOPY:T
Shan Khan
Masters in Machine Learning, currently working in Data Scientist and Experience of more than 7 years in IT dealing with wide range of applications and platforms, experience within multi-tier environments, analysis, design, consultation and teams leading roles. Delivered/ deployed mission critical applications/ solutions for worldwide customers on highly availability productions environments. Expertise: ➢ Machine Learning and Natural Language Processing ➢ Implementing DevOps process inside Team ➢ Micro services and Azure App Service ➢ Worked in Dynamics 365 Integration Product Development ➢ Worked in SAP HCM Module Product Development ➢ System Analysis and Design More Details on my resume available @ Developer Story
Updated on June 04, 2022Comments
-
Shan Khan almost 2 years
Following is my command to copy the files in my computer and from my computer to network.
ROBOCOPY "K:\Builds" F:\Builds\ /E /COPY:DAT ROBOCOPY "E:\" "K:\Shan Khan\" /E /COPY:DAT
How i can make timestamp in destination folder only when copying the file for example
"K:\Builds" when copied to F:\Builds\
F:\Builds\ ---> F:\Builds_26092015
"E:\" when copied to "K:\Shan Khan\Workspace"
"K:\Shan Khan\Workspace"---> "K:\Shan Khan\Workspace_26092015"
Kindly note that K drive is password protected and i manually saved the password while mapping the IP address to K drive.
-
MethodMan over 7 yearshow would one format this so that it picks up and renames the files with the filename + a current time stamp?
Start /WAIT robocopy %EFM_TEMP% %EFM_BACKUP% *.CFX /S /NP /R:5 /W:5 /XX /MOV /LOG:%EFM_COPY_BACKUP%
-
Mofi over 5 years@ShanKhan What is the purpose to run cmd line
date /T
in a separate command process started with%ComSpec% /C
byfor
in background to output the country dependent current date, capture this output, process it byfor
with superfluoustokens=1*
after startedcmd.exe
terminated, get the captured line assigned completely to environment variabledatestr
and then don't use this environment variable at all? Value of environment variabledatestr
is always identical to value of dynamic environment variabledate
as used on second line. The entirefor
cmd line takes just CPU power. -
Mofi over 5 years@ShanKhan The command line
md F:\Builds\"%date:/=_%"
is also coded wrong. The entire folder path must be enclosed in double quotes and not just a part of it. Windows command processor corrects this syntax error on execution ofmd
automatically, but not all commands and applications fix automatically such an incorrect double quoted argument string. The second line correct coded would bemd "F:\Builds\%date:/=_%"
. The help output on running in a command prompt windowcmd /?
explains on last help page in last paragraph when and how a file/folder name must be enclosed in double quotes. -
Mofi over 5 years@ShanKhan Better would be using a date format like
YYYY-MM-DD
(standardized international date format) orYYYY_MM_DD
orYYYYMMDD
. The folders listed alphabetically with first year with four digits, second month with two digits and third day with two digits are listed in this case automatically also in chronological order which makes it easy for people to find the folder for a specific date and for scripts to process the date in folder name more easily. Delete oldest folder? A single command line with such a date format in folder name.