1.

Solve : saving variable as a file for later use?

Answer»

Hi,

I know this will be a real EASY question for most of you. I use the bat script below to back up files from one computer to another. What I want to do is save the value of the %input% variable to a file at the root of C:\. I have another batch file that I run on a new computer that will RESTORE all the files I have backed up. I would like that bat script to read the value in the file on C:\ of the backup computer and assign it to the %INPUT% variable on the new computer. In essence what I want to do is transfer the value of a variable from one computer to another. I am not a programer, I just did some cutting, pasting, and modifying to make this script, so go easy on me. Thanks in advance for your help.

Charlie

@echo off
echo Enter Computer Name You are Transfering Files From and Press ENTER:
REM This gets the From Computer Name and stores it as %Input% variable
FC con nul /lb1 /n |FIND "1:" > %temp%.\t1.bat
echo e102'set %%1='> %temp%.\t2.dat
for %%? in (w q) do echo %%?>> %temp%.\t2.dat
DEBUG %temp%.\t1.bat < %temp%.\t2.dat > nul
call %temp%.\t1.bat INPUT
for %%? in (t1.bat t2.dat) do del %temp%.\%%?
Echo
echo Enter Computer Name You are Transfering Files To and Press ENTER:
REM This gets the To Computer Name and stores it as %Input1% variable
FC con nul /lb1 /n |FIND "1:" > %temp%.\t1.bat
echo e102'set %%1='> %temp%.\t2.dat
for %%? in (w q) do echo %%?>> %temp%.\t2.dat
DEBUG %temp%.\t1.bat < %temp%.\t2.dat > nul
call %temp%.\t1.bat INPUT1
for %%? in (t1.bat t2.dat) do del %temp%.\%%?
Echo
:BEGIN
CLS
ECHO PLEASE CHOOSE THE MACHINE YOU ARE TRANSFERING FILES FROM
ECHO (1) OS
ECHO (2) OSJ
ECHO (3) CD
CHOICE /N /C:123 PICK A NUMBER (1, 2, or 3)%1
REM - THE NEXT THREE LINES ARE DIRECTING USER DEPENDING UPON INPUT
IF ERRORLEVEL ==3 GOTO THREE
IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE
GOTO END
:THREE
mkdir \\%INPUT1%\c\%INPUT%
mkdir \\%INPUT1%\c\%INPUT%\Cd
xcopy /E C:\Cd \\%INPUT1%\c\%INPUT%\Cd
GOTO END
:TWO
mkdir \\%INPUT1%\c\%INPUT%
mkdir \\%INPUT1%\c\%INPUT%\Jr
xcopy /E C:\Jr \\%INPUT1%\c\%INPUT%\Jr
GOTO END
:ONE
mkdir \\%INPUT1%\c\%INPUT%
mkdir \\%INPUT1%\c\%INPUT%\Os
xcopy /E C:\Os \\%INPUT1%\c\%INPUT%\Os
:END
EXIT

Before someone goes blind reading your post:

Is this a Windows machine and if so what version?

What is the DEBUG program you create on the fly expected to do?

Let us know. Hi,

I am writing this batch file on a windows 98 machine. The code I posted basically copies specified files on the machine it is run on to another computer (as specified by %Input1%) and to a specific folder (as specified by %input%).

When I setup a new machine I will need to copy said files onto the new machine. I want to be able to run a batch file on the new machine that will do this. I would like the bat file to be able to read the original %Input% value as originally assigned. Hope that makes a little more sense. Thanks for your help.

ChalrieThere is a NIFTY little utility Answer that will eliminate half your file.

ANSWER allows you to prompt for user data and store it in the environment space. Each time it runs the environment variable is overwritten, so be sure to save each value to your own variables. Put into a directory along your path and you can use it anywhere.

Code: [Select]
answer Enter Computer Name You are Transfering Files From:
set from=%answer%
answer Enter Computer Name You are Transfering Files To:
set to=%answer%
:BEGIN
.
.
.


Using fc to prompt for input is an old DOS trick which may not work anymore in Windows, CON and NUL are invalid in this context.

Good luck.



Discussion

No Comment Found