|
Answer» I need to be able to "save" a variable for use LATER in anouther bat file. I am using the date and time as a variable, and once my 1st bat file runs and CLOSES I have other bat's I want to run later using the same date and time but it doesn't "remember" what it used earlier. I am almost positive this is possible I just dont know how to pull it off. Any help or suggestions are appreciated.I'm no DOS hacker, but surely you could export the value to an environment variable, eg SET VARIABLE=value?Do you mean something like this?
SET myName = ikeAtCyber
If so, this is what I have been trying but, say I have anouther bat file that I want to use the same variable, I can't do this
echo %myName%
in the 2nd file and get ikeAtCyber. It is just blank. If there is a way to save the variable even if dos is closed that is what I am looking for.
ThanksAh, sorry, I don't know how to preserve environment variables between different cmd.exe or command.com sessions.Do you know if it is possible to set a variable equal to a filename? For example if in my 1st bat I create a .txt file at say c:\temp\123.txt. Can I set the variable equal to something like c:\temp\*.txt that would make my variable 123, or even 123.txt? I hope this all makes sense. ThanksThere a multiple ways to make variable persistent, here is what I would do:
In batch 1: Code: [Select]::--- load date and time into variables set vtime=%time% set vdate=%date%
::--- make variables persistent, by storing SET commands ::--- into separate batch type nul>"%TEMP%.\persist.cmd" echo set vtime=%vtime%>>"%TEMP%.\persist.cmd" echo set vdate=%vdate%>>"%TEMP%.\persist.cmd"
::--- use vtime and vdate echo vtime=%vtime% echo vdate=%vdate% ...In batch 2: Code: [Select]::--- restore persistent variables by running persist.cmd "%TEMP%.\persist.cmd"
::--- use vtime and vdate echo.vtime=%vtime% echo.vdate=%vdate% ...To set a variable to a file name that fits a file mask do this: set variable= for %%a in ("c:\temp\*.txt") do @set variable=%~na echo.filename without extension='%variable%' for %%a in ("c:\temp\*.txt") do @set variable=%~nxa echo.filename with extension='%variable%'
For more info regarding the %~ BUSINESS type for /? at a command LINE or look @ "http://www.cmdtips.com/dostips/DosCommandRef.htm#for" For more info regarding persistency look @ "http://www.cmdtips.com/dostips/DtTutoPersistency.php"
Hope this helps
|