hey hey
hey hey

Reputation: 247

Can i reference a variable in my xcopy path?

@echo off
set /p fileToCopy = "File you want to copy: "
set /p destinationFile = "Destination file (On Desktop): "
xcopy c:\users\jordean\desktop\%fileToCopy% c:\users\jordean\desktop\%destinationFile%
pause

Why does this not work? Am I using variables incorrectly? First day using command line and batch files.

Upvotes: 3

Views: 8947

Answers (1)

aschipfl
aschipfl

Reputation: 34979

You need to remove the SPACE before =, otherwise it becomes part of the variable name:

@echo off
set /P fileToCopy="File you want to copy: "
set /P destinationFile="Destination file (On Desktop): "
xcopy "C:\users\jordean\desktop\%fileToCopy%" "C:\users\jordean\desktop\%destinationFile%"
pause

Upvotes: 7

Related Questions