A Windows XP help forum. PCbanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » PCbanter forum » Microsoft Windows XP » Customizing Windows XP
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Batch Files in Win XP using Variables



 
 
Thread Tools Display Modes
  #1  
Old May 18th 07, 03:48 PM posted to microsoft.public.windowsxp.customize
VexedFist
external usenet poster
 
Posts: 3
Default Batch Files in Win XP using Variables

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.
Ads
  #2  
Old May 18th 07, 09:21 PM posted to microsoft.public.windowsxp.customize
trs51x
external usenet poster
 
Posts: 3
Default Batch Files in Win XP using Variables

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!


"VexedFist" wrote in message
...
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.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off






All times are GMT +1. The time now is 02:44 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 PCbanter.
The comments are property of their posters.