Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I made a Batch file that allows me to move files to one hard drive to the next hard drive. There is just one thing I would like to add to it. I want the CMD to prompt me to what user account its going to.

Example: xcopy /s/z D:\"Documents and Settings"\%username%\Desktop C:\Users\USER\Desktop

Where is says "USER" need to add the user account to which one its going to. Example. xcopy /s/z D:\"Documents and Settings"\%username%\Desktop C:\Users\Dang\Desktop

So What I am looking for is when i Start the .Bat file it will ask me what "User account" would you like to transfer the data to? Than I would be able to add the name I want in there.

share|improve this question

You can prompt the user to enter a string with the /p-flag on the set command, e.g.:

set /p targetuser="Enter target username: "
xcopy /s/z "D:\Documents and Settings\%username%\Desktop" "C:\Users\%targetuser%\Desktop"

For use in scripting, it is often beneficial to avoid halting for user input. The following line would use the first parameter supplied to your batch file instead and execute without interruptions:

xcopy /s/z "D:\Documents and Settings\%username%\Desktop" "C:\Users\%~1\Desktop"
share|improve this answer
Why did you add a ~? to the second script? – David Dec 12 '12 at 17:56
As documented here, the tilde is a modifier that strips surrounding quotes off the parameter. That way, the script will not break under either copy.bat Daniel Doe or copy.bat "Daniel Doe". – Marcks Thomas Dec 12 '12 at 18:03
This worked! :) set /p targetuser="Enter target username: " xcopy /s/z "D:\Documents and Settings\%username%\Desktop" "C:\Users\%targetuser%\Desktop" – Daniel Dec 12 '12 at 18:11

The easiest way to do this is with a command line parameter:

xcopy /s/z D:\"Documents and Settings"\%username%\Desktop C:\Users\%1\Desktop

Then run the script like so:

C:>sciptname.bat username
share|improve this answer
Well I dont want to change the D Drive Username. I want to change the one going to the C Drive. – Daniel Dec 12 '12 at 17:44
I tried doing the scriptname.bat Username but it makes it unusable – Daniel Dec 12 '12 at 17:49
I've edited the script to reflect your comment. – David Dec 12 '12 at 17:52
Could you please expand on "makes it unusable"? – David Dec 12 '12 at 17:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .