Link to home
Start Free TrialLog in
Avatar of Orchard
Orchard

asked on

Need to Copy a folder to a new location and append copied folder with date and time

Hi, I need some help please

I have a requirement to copy a folder "folderA" to a new location and append the copied folder with the date and time ie "folderA_date_time" from within a batch file.

Any help greatly appreciated.

Many thanks
Avatar of knightEknight
knightEknight
Flag of United States of America image

It depends on the default date/time format of your system.  Please run the following command at a command prompt and post the results here:

  echo %date% %time%
Avatar of Orchard
Orchard

ASKER

Hi Knight

the result is

05/05/2011 16:33:32:01

ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
unfortunately there is a bit of ambiguity in todays date - 05/05/2011.  Is that MM/DD/YYYY or is it DD/MM/YYYY ... and which way do you want it in the folder name?
(personally I recommend YYYYMMDD for sorting purposes)
Avatar of Orchard

ASKER

Yes I agree YYYYMMDD would be great
well, if your system date format is MM/DD/YYYY then use this:

  set NEWFOLDERNAME = "folderA_%date:~6,4%%date:~0,2%%date:~3,2%_%time:~0,2%%time:~3,2%%time:~6,2%"

but if your system date format is DD/MM/YYYY then use this:

  set NEWFOLDERNAME = "folderA_%date:~6,4%%date:~3,2%%date:~0,2%_%time:~0,2%%time:~3,2%%time:~6,2%"
(I mean use that line in the script posted above)
Avatar of Orchard

ASKER

Hi Knight

I had to remove the spaces before and after the = in the set NEWFOLDERNAME line, but other than that it works a dream

Many thanks
Good catch on the spaces!  That one gets me every time.  Glad it works!