Batch file variable creation

July 21, 2006 at 12:00:57
Specs: WinXP Home Sp2, AMD 2000/512mb

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!


See More: Batch file variable creation

Report •


#1
July 21, 2006 at 12:11:55

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!


Report •

#2
July 21, 2006 at 13:41:00

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

Do yourself a favor BACKUP!


Report •

#3
July 21, 2006 at 15:18:11

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


Report •

Related Solutions

#4
July 21, 2006 at 17:20:33

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



Report •

#5
July 21, 2006 at 19:40:20

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!


Report •

#6
July 23, 2006 at 07:50:45

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---..


Report •

#7
July 26, 2006 at 09:53:24

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.


Report •


Ask Question