Computing.Net > Forums > Programming > enter variable in batch 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.

enter variable in batch file

Reply to Message Icon

Name: bobbby
Date: June 26, 2006 at 11:21:23 Pacific
OS: XP
CPU/Ram: P4 3.2Ghz 1024mb
Product: ?
Comment:

Hi everybody,

I’m trying to make a batch file that copies some files from one place to another. The filenames contain a client number so they differ each time (for example client123.doc or client123.dat).
I’m hoping to make a script that asks for the client number and then it automatically uses that number in all copy commands.

So for example:

You run the script.
The script asks for a client number.
You enter “123”.
The script copies all files that contain 123 to a certain folder.


My script so far looks like this:

@echo off

Copy "C:\windows\version 1\*123.*" "C:\clients" /y
Copy "C:\windows\version 2\*123.*" "C:\clients" /y
Copy "C:\windows\version 3\*123.*" "C:\clients" /y
Copy "C:\windows\version 4\*123.*" "C:\clients" /y
Copy "C:\Program Files\AA\*123.*" "C:\clients" /y

Exit

But this doesn’t really work, because you would have to change the client number in each line. How could I automate this?




Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 26, 2006 at 12:46:54 Pacific
Reply:

Modify your script as below

@Echo Off

Set /P Client=Enter Client Number^>

Copy "C:\windows\version 1\*%Client%.*" "C:\clients" /y
Copy "C:\windows\version 2\*%Client%.*" "C:\clients" /y
Copy "C:\windows\version 3\*%Client%.*" "C:\clients" /y
Copy "C:\windows\version 4\*%Client%.*" "C:\clients" /y
Copy "C:\Program Files\AA\*%Client%.*" "C:\clients" /y

Of course that is a straightforward enhancement as the input should be checked too, but this would take us far away.


0

Response Number 2
Name: bobbby
Date: June 26, 2006 at 13:46:31 Pacific
Reply:

Thank you so much! It works great!
Before your post Ive been searching for an answer myself, but it quickly became too complicated. I knew something simple like this would exist...

Unrelated question:
Do you know what a generic path description to your desktop is?
"%UserProfile%\Desktop\" only works with an English OS...



0

Response Number 3
Name: IVO
Date: June 26, 2006 at 14:09:43 Pacific
Reply:

I'm not absuletely sure about what I'm answering to your question related to the desktop's path, but I'm running an italian edition of Windows XP SP2 and what you posted would work for me too.

I suppose the path composed with %UserProfile% variable would be language invariant.


0

Response Number 4
Name: bobbby
Date: June 26, 2006 at 14:45:23 Pacific
Reply:

Ive got a dutch version of XP and the desktop is called "bureaublad".
if i use something like
"explorer.exe "%USERPROFILE%\desktop\Data"
to open a folder on my desktop in explorer, it gives an error. Ive got to use the dutch word "bureaublad" in the path.


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 Programming Forum Home


Sponsored links

Ads by Google


Results for: enter variable in batch file

Nesting variables in batch files ? www.computing.net/answers/programming/nesting-variables-in-batch-files-/14334.html

Variables in Batch Files www.computing.net/answers/programming/variables-in-batch-files/14347.html

Prompt for Variable in Batch File www.computing.net/answers/programming/prompt-for-variable-in-batch-file/12508.html