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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|