2

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

  1. "K:\Builds" when copied to F:\Builds\

        F:\Builds\ ---> F:\Builds_26092015
    
  2. "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.

Shan Khan
  • 9,667
  • 17
  • 61
  • 111

1 Answers1

1

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
aschipfl
  • 33,626
  • 12
  • 54
  • 99
Shan Khan
  • 9,667
  • 17
  • 61
  • 111
  • how 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%` – MethodMan Sep 01 '16 at 14:17
  • @ShanKhan What is the purpose to run cmd line `date /T` in a separate command process started with `%ComSpec% /C` by `for` in background to output the country dependent current date, capture this output, process it by `for` with superfluous `tokens=1*` after started `cmd.exe` terminated, get the captured line assigned completely to environment variable `datestr` and then don't use this environment variable at all? Value of environment variable `datestr` is always identical to value of dynamic environment variable `date` as used on second line. The entire `for` cmd line takes just CPU power. – Mofi Jan 08 '19 at 18:22
  • @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 of `md` automatically, but not all commands and applications fix automatically such an incorrect double quoted argument string. The second line correct coded would be `md "F:\Builds\%date:/=_%"`. The help output on running in a command prompt window `cmd /?` explains on last help page in last paragraph when and how a file/folder name must be enclosed in double quotes. – Mofi Jan 08 '19 at 18:29
  • @ShanKhan Better would be using a date format like `YYYY-MM-DD` (standardized international date format) or `YYYY_MM_DD` or `YYYYMMDD`. 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. – Mofi Jan 08 '19 at 18:35