Computing.Net > Forums > Programming > Batch script: Help with FOR file IO

Batch script: Help with FOR file IO

Reply to Message Icon

Original Message
Name: stephenturns
Date: November 30, 2006 at 04:24:14 Pacific
Subject: Batch script: Help with FOR file IO
OS: Windows XP SP2
CPU/Ram: P4 / 1GIG RAM
Comment:

Hi,
I want to store variables in a temp file and to be able to call those variables for usage in the batch file.

Im not sure how to manipulate the FOR command for this. I want to be able to store variables in that temp file and also I want to be able to search the temp file for the variable.

My plan for the temp file is as follows:
------
VARIABLES:
INT1: VAR1
INT2: VAR2
CHAR1: VAR3
CHAR2: VAR4
------
Any help regardless of the FOR command usage would be greatly appreciated.
Thanx for you help :)


Report Offensive Message For Removal


Response Number 1
Name: tonysathre
Date: December 1, 2006 at 11:38:07 Pacific
Subject: Batch script: Help with FOR file IO
Reply: (edit)

I noticed you are using int and char datatypes. Batch scripts do not use special datatypes and are not defined in the script.

"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 2
Name: stephenturns
Date: December 1, 2006 at 12:54:24 Pacific
Subject: Batch script: Help with FOR file IO
Reply: (edit)

Thanx for your comments tonysathre,
The datatypes are only for my reference. When i create a local variable within a batch script i like to be as discriptive as possible. It just lets me know what the variable is used for throughout the script.


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: December 2, 2006 at 00:05:38 Pacific
Subject: Batch script: Help with FOR file IO
Reply: (edit)

Is your goal to set, for instance:

INT1=VAR1

?


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal

Response Number 4
Name: stephenturns
Date: December 2, 2006 at 03:49:34 Pacific
Subject: Batch script: Help with FOR file IO
Reply: (edit)

Mechanix2Go,
A better example than the one above would be:
---%temp%\~atempfile.tmp
VARIABLES
Date=%date%
Time=%time%
Name=%stringName%
---
I want to store variables, from batch file execution, into a temp file and call those variables back into the batch file when requested.
Im having trouble putting the variables where I would like them to go, for example the variables %stringName% to be placed after the Name= in the temp file.
Im also having trouble storing those variable values into "fresh" variables in the batch script.


Report Offensive Follow Up For Removal

Response Number 5
Name: Mechanix2Go
Date: December 2, 2006 at 11:37:55 Pacific
Subject: Batch script: Help with FOR file IO
Reply: (edit)

With those lines in myfile.tmp you can:

for /f "tokens=*" %%V in (%TEMP%\myfile.tmp) do set %%V

BTW, reassigning built-in vars lije TIME and DATE is generally not a good idea.


=====================================
If at first you don't succeed, you're about average.

M2



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch script: Help with FOR file IO

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge