Batch Files in Win XP using Variables

G

Guest

I am trying to write a batch file for use in Windows XP.
Here is what I have now:

CD\
CD..
cd Temp Data Files
cd Raw Data
del lexall
del lexall.out
rename lexall.txt lexall.
9005LEX.EXE

I need to change the lexall.txt file name to include a user variable:

1234567_lexall.txt

The Number 1234567 needs to be input by the user every time.
Does anybody have any ideas?

Any and all suggstions will be welcome.
 
T

trs51x

FYI, in this context what you want to use are called "arguments". In the
batch context, "variables" actually refers to something slightly different.

Your batch file should read:

CD\
CD..
cd Temp Data Files
cd Raw Data
del lexall
del lexall.out
rename %1_.txt lexall.
9005LEX.EXE

You would execute it from a command prompt like so:

runbatch 1234567

assuming the batch file name is "runbatch.bat".

If you intend for the 1234567 to be part of the new destination filename as
well, you need to use the %1 there, too, i.e.:

rename %1_.txt %1.

....

Now on to the optimization!

The first four lines of your file can all be combined into one line:

cd\Temp Data Files\Data Files

Note that you don't need to "cd\" then "cd..". "cd\" puts you at the root
(the top level); there is no ".." above that.

Also, not sure if the folder names you give are the actuals or just
placeholders for sake of this discussion, but if they are actual, it is a
good practice to place any file/folder name with spaces in it inside double
quotes, i.e.:

"cd\Temp Data Files\Data Files"

So, all things considered, your final complete batch file should read:

"cd\Temp Data Files\Data Files"
del lexall
del lexall.out
rename %1_.txt lexall.
9005LEX.EXE

Note this code is untested and unwarrantied. Use at your own risk!

Some good reference sites:

http://commandwindows.com/

http://www.ericphelps.com/batch/index.htm

The Eric Phelps site is technically about DOS / win9x, but most of the
techniques described there can still be applied in XP.

Good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top