We help IT Professionals succeed at work.

Embedding strings in MS DOS Batch File

Ray Turner
Ray Turner asked
on
136 Views
Last Modified: 2017-03-28
How do I get this to work?

set datecheck=01/01/1900 
set sourceDrive=H
xcopy "%sourceDrive%:\sync\Users\zzz\Documents\My Crazy Data\*" "C:\Users\zzz\Documents\My Crazy Data\"  /s /y /e /v /d:%datecheck%

Open in new window

Basically, I want to embed the value of variable sourceDrive in the string.

Thanks
Comment
Watch Question

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
That looks fine, what problem are you having?

~bp
Ray TurnerSenior Consultant

Author

Commented:
This line executes fine

xcopy %sourceDrive%:\sync\vbapps\* c:\vbapps\  /s /y /e /v /d:%datecheck%

However, oddly this fails
set datecheck=01/01/1900
set sourceDrive=H
xcopy "%sourceDrive%:\sync\Users\zzz\Documents\My Crazy Data\*" "C:\Users\zzz\Documents\My Crazy Data\"  /s /y /e /v /d:%datecheck%
NVITEnd-user support
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
When you say it fails, please share what the error is, etc.

~bp
Ray TurnerSenior Consultant

Author

Commented:
The xcopy does not execute.  It appears that if the path contains spaces xcopy fails to execute.
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Ray TurnerSenior Consultant

Author

Commented:
Doh!  Thanks!  A 2nd pair of eyes works miracles!
Ray TurnerSenior Consultant

Author

Commented:
Thanks!
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Welcome, glad that was helpful.

~bp
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.