knedlpavr
knedlpavr

Reputation: 11

Batch copy script with user prompting

If I following syntax, everything works.

xcopy source destination /e

but when I want to make it a script in next fashion:

set /p src = Enter source directory: 
set /p dest = Enter destination directory: 

xcopy "%src%" "%dest%" /e

pause

then it doesn't work. It gives me Invalid drive specification. %src% and %dest% are usually c:/somedirectory

Upvotes: 1

Views: 64

Answers (2)

Stephan
Stephan

Reputation: 56155

%src% and %dest% are not defined. What you have defined, is %src % and %dest %.
Batch is a bit picky with usage of spaces. Correct is:

set /p "src=Enter source directory: "
set /p "dest=Enter destination directory: "

xcopy "%src%" "%dest%" /e

pause

Note the missing spaces around the = and the quotes and their position.
(the quotes are not really neccessary, but they help to define exactly where your string ends and avoids problems with some special characters)

Upvotes: 1

Florian Straub
Florian Straub

Reputation: 856

Works fine without blanks after the variable:

set /p src=Enter source directory: 
set /p dest=Enter destination directory: 
xcopy "%src%" "%dest%" /e

pause

Upvotes: 0

Related Questions