Computing.Net > Forums > Windows Server 2003 > Batch File to Copy File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File to Copy File

Reply to Message Icon

Name: JohnRChick
Date: April 30, 2005 at 18:24:00 Pacific
OS: 2003
CPU/Ram: 2.5/1/25
Comment:

Hello. I'm trying to create a batch file that will copy one file from one place to another. I need to use the %username% function since this will be used on a several different computers. Heres what I have, but its not working!

copy C:\Performance.txt to C:\Docume~1\%username%

- I can copy the file to the \Docume~1 folder, but I can never get the %username% thing to work! I tried shortening it, with ~1, etc but it still wont work! Sometimes it makes a new file instead. I tried this:

copy C:\Performance.txt to C:\Docume~1\%users~1

and that still doesnt work. Any ideas?



Sponsored Link
Ads by Google

Response Number 1
Name: Curt R
Date: May 2, 2005 at 05:12:37 Pacific
Reply:

Try using double quotes around the string containing the long names:

Ex:

copy c:\performance.txt "C:\documents and settings\%username%"


0

Response Number 2
Name: Curt R
Date: May 2, 2005 at 05:15:55 Pacific
Reply:

Oh shoot...I just realized. in order to use the %username% variable, it needs to pull that info from somewhere. Without an actual username to associate the variable to the file copy will go nowhere. So the question is: where/how are you getting the username?

My above example should work on as a batch file on a local PC and the variable would use the username of the person presently logged onto the the local PC.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows Server 2003 Forum Home


Sponsored links

Ads by Google


Results for: Batch File to Copy File

Batch script for copying files www.computing.net/answers/windows-2003/batch-script-for-copying-files/6487.html

Batch file to check a file in Unix www.computing.net/answers/windows-2003/batch-file-to-check-a-file-in-unix-/6057.html

Batch File Problem! www.computing.net/answers/windows-2003/batch-file-problem/5941.html