Computing.Net > Forums > Programming > Batch file variable creation

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 variable creation

Reply to Message Icon

Name: ham30
Date: July 21, 2006 at 12:00:57 Pacific
OS: WinXP Home Sp2
CPU/Ram: AMD 2000/512mb
Product: generic
Comment:

I need to learn how to create a batch file variable of a file or folder name to use several times later in the batch file. I've tried several ways and haven't figured out how to do it. One example that didn't work was:

set /p Name=file1.dat
mkdir c:\%Name%

Can someone show me the correct way? And also a link to a good XP batch tutorial would be very helpful. I found one (
http://www.ss64.com/ntsyntax/index.html), but it wasn't enough help.


Do yourself a favor BACKUP!



Sponsored Link
Ads by Google

Response Number 1
Name: ham30
Date: July 21, 2006 at 12:11:55 Pacific
Reply:

Jeez, I'm a dummy! Change the above trial to:

set /p Name=Folder1
mkdir c:\%Name%

That looks more logical.

Do yourself a favor BACKUP!


0

Response Number 2
Name: ham30
Date: July 21, 2006 at 13:41:00 Pacific
Reply:

Nevermind, sorry to bother you. I removed the '/p' and it worked.

Do yourself a favor BACKUP!


0

Response Number 3
Name: Shr0Om
Date: July 21, 2006 at 15:18:11 Pacific
Reply:

You use /p if you want some input assigned to the variable.

i.e user input

set /p Name=What is your name?:
echo Hello %Name% & pause

file input

set /p Variable=<Somefile.txt
This would assign the string from the first line of the txt file to the variable.

If you google for "batch file tutorial" im sure you will find some useful pages


0

Response Number 4
Name: Mechanix2Go
Date: July 21, 2006 at 17:20:33 Pacific
Reply:

Hi ham30,

Sadly, most sites I've seen are either rather trivial or so arcane that they're for freaks only. Much depends on what stage of the journey you're in.

One individual whose work helped me was Laura Fairhead.

In NT CMD many things which were ball breakers in DOS are relatively simple.


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 5
Name: ham30
Date: July 21, 2006 at 19:40:20 Pacific
Reply:

Thanks guys.

Yeah Shr0Om I finally figured out that I didn't want the /p. I had misinterpreted the instructions on that web site.
I've Googled for batch file tutorial and seemed to get nothing but old DOS batch file help. I Googled for "XP batch file tutorial" and only found the one. Anyway, I got the job done that I was working on.

Hi Mechanix, I checked out Laura Fairhead's web site. She has several batch files to get ideas from, thanks. I did a little simple DOS batch file creating many years ago, but I'm really rusty and my mind isn't what it used to be. I've decided not to try learning the new NT batch stuff.


Do yourself a favor BACKUP!


0

Related Posts

See More



Response Number 6
Name: Shr0Om
Date: July 23, 2006 at 07:50:45 Pacific
Reply:

M2: I checked out Laura Fairhead's site aswell.. Pretty harcore batch programming there..
Like, a chess game written entirely in batch..
Pity it wont work under XP, i would like to see how it works.

Also enjoyed those graphics demos written in assembly. Amazing how they do that s---..


0

Response Number 7
Name: tonysathre
Date: July 26, 2006 at 09:53:24 Pacific
Reply:

Wow, I think I'm going to install DOS on one of my old boxes just so I can see some of those batch files at work. That chess script is the most complex batch programming I've ever seen.

UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus.


0

Sponsored Link
Ads by Google
Reply to Message Icon






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: Batch file variable creation

batch file variable reset www.computing.net/answers/programming/batch-file-variable-reset/16220.html

Batch file variables www.computing.net/answers/programming/batch-file-variables/16799.html

Batch File Variable Help www.computing.net/answers/programming/batch-file-variable-help/17718.html