Link to home
Start Free TrialLog in
Avatar of PDSWSS
PDSWSS

asked on

Why is the date not added to the saved folder in the attached code?

I would like to back up the contents of a folder "eDIGSNEW"  into a folder named "eDIGS" on the "F:" drive
with current date and time to be added to the folder each day it is saved.
The attached code runs but does not add the date and time to the folder. How should this code be modified so that the current date is added to the "eDIGSNEW" folder everytime it is saved. Thanks
@echo off
:: variables
set drive=F:\Backup
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /y

%backupcmd% "C:\shared$\eDIGSNEW" "%drive%\eDIGS"

echo Backup Complete!
@pause

Open in new window

Avatar of knightEknight
knightEknight
Flag of United States of America image

@echo off
:: variables
set drive=F:\Backup
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /y

md "%drive%\eDIGS_%folder%"

%backupcmd% "C:\shared$\eDIGSNEW" "%drive%\eDIGS_%folder%"

echo Backup Complete!
@pause
oops, i put the date on the wrong folder:

@echo off
:: variables
set drive=F:\Backup
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /y

md  "C:\shared$\eDIGSNEW_%folder%"

%backupcmd% "C:\shared$\eDIGSNEW_%folder%" "%drive%\eDIGS"

echo Backup Complete!
@pause
actually, the first one may have been right after all -- I'm confused by your last sentence: "...the current date is added to the "eDIGSNEW" folder" - I think you mean the eDIGS folder instead, correct?

I'm adding an echo statement for clarity:

@echo off
::variables
set drive=F:\Backup
set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy/s/c/d/e/h/i/r/y

md "%drive%\%folder%"

@echo %backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"
%backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"

echo Backup Complete!
@pause
Avatar of PDSWSS
PDSWSS

ASKER

Yes. That was a mistake. The date should appear on the "eDIGS" folder. Thanks
Note that I added eDIGS to the folder variable in my most recent post:  
set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
Avatar of PDSWSS

ASKER

What is the meaning of /s /c /d /e /h /i /r /y?  Thanks
Avatar of PDSWSS

ASKER

Tested your code. Did not add date to the eDIGS Folder.
See error message. I had another folder in the Backup Folder = eDIGS3.15.11

It says the folder it is attempting to create already exists and then creates an eDIGS folder without the date.
Picture-3.png
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
To see the meaning of the XCOPY options, do this at a command prompt:

xcopy /?
Avatar of PDSWSS

ASKER

What is the meaning of these letters    /s /c /d /e /h /i /r /y?
Avatar of PDSWSS

ASKER

Used your latest code exactly and got exactly the same result =   F:\BAckup\eDIGS

NO DATE is added to the end of the eDIGS folder.  
please run this at a command prompt and post the result here:


set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
echo %folder%
Avatar of PDSWSS

ASKER

C:\Users\Administrator>

now post the result of this command:

date/t
Avatar of PDSWSS

ASKER

see attached
Picture-4.png
Avatar of PDSWSS

ASKER

Any ideas about the issue here?
you used the wrong slash:  use / instead of \  as in date/t

You will need to press CTRL-C to break out of the date prompt above (if it is still like that).
also, in addition to date/t please re-run the following and paste another screenshot as you did above:

set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
echo %folder%
Avatar of PDSWSS

ASKER

Screen shot attached. Thanks
Picture-4.png
this is two separate commands:

first run:
set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%

THEN run:
echo %folder%
Avatar of PDSWSS

ASKER

Screen shot attached -
Picture-2.png
That is the expected result.  Do me a favor and cut-n-paste this into a separate batch file and show the result here.  It won't do anything, it just echos the commands.


@echo off
setlocal

::variables
set drive=F:\Backup
set folder=eDIGS_%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy/s/c/d/e/h/i/r/y

ECHO md "%drive%\%folder%"

ECHO %backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"
REM  %backupcmd%  "C:\shared$\eDIGSNEW"  "%drive%\%folder%"

REM echo Backup Complete!
REM @pause

Open in new window

Avatar of PDSWSS

ASKER

I cut and pasted into notepad and saved as a .cmd file. Ran it and it did nothing as you said.  Screen shot of cut and paste is attached. Is that what you are looking for?
Picture-5.png
sorry, i get what you are doing now.  I didn't realize you would be double-clicking it.  (I run .cmd files from a command prompt, but either way works.)

Remove the word "REM" before @pause on the last line -- save it and run it again.
Avatar of PDSWSS

ASKER

I can not cut and paste into the cmd prompt. Can you?
Avatar of PDSWSS

ASKER

Screen shot attached. Looks like your code works.
Something I forgot to mention. The first time I ran your code, I got a message that it could not be saved because this file already existed and it displayed eDIGS_2011_03_16 in the message. This is very strange since there never was such a file in the F:\backup folder.  I'm going to create another folder and try saving into a different folder.
Thanks,
Picture-1.png
Actually, you can cut-n-paste to a command prompt by setting the "Quick Edit" option, but don't worry about that now, it isn't important.

The output shows that the script is working as expected -- assuming you are specifying the correct source directory to be backed up.

Let's try a simpler version that doesn't use all the variables (which aren't really necessary)
@echo off
 setlocal

 set today=%date:~10,4%_%date:~4,2%_%date:~7,2%

 if not exist "C:\shared$\eDIGSNEW\*" echo No files exist in "C:\shared$\eDIGSNEW"  & exit/b

 md "F:\Backup\eDIGS_%today%" >nul

 xcopy/s/c/d/e/h/i/r/y  "C:\shared$\eDIGSNEW"  "F:\Backup\eDIGS_%today%"

 echo Backup Complete!
@pause

Open in new window

Avatar of PDSWSS

ASKER

Tried to email this about 20 minutes ago but EE site was unavailable.  PROBLEM SOLVED.

Looks like I made a mistake and left out two of the "%"  Sorry about that.  Thought I cut and pasted it in but must not have.

If I could, I'd give you more points for the extra effort you put in.  I appreciate your sticking with this.

Have a great day.
Avatar of PDSWSS

ASKER

Thanks for the extra effort.
Excellent solution+++
Avatar of PDSWSS

ASKER

I gave you the highest scores and yet they scored it at 7.8 - very good?
Whatever algorithm they use to calculate the score needs to be updated.
Does not reflect the actual process. Thanks again.
no worries, i've never understood the scoring anyway.  :)