Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Reading a value from a file, then comparing it?  (Read 4350 times)

0 Members and 1 Guest are viewing this topic.

PPowerHouseK

  • Guest
Reading a value from a file, then comparing it?
« on: December 13, 2009, 01:59:56 PM »
Hello all,

I am trying to have this batch store a variable read from a file with  value inside of it.
Here is what I have so far, but it seems it cannot set the variable. This is bewildering.
Code: [Select]
@echo off
cd %userprofile%
for /f "delims=" %%a in (code.ini) do (
echo %%a
set code= <code.ini
)
ECHO Code is:
ECHO '%code%'
Which results in this:
Code: [Select]
a1b2C3d4e5
 ECHO is off.
Code is:
''
Perhaps I have the syntax wrong?

Any helpful advice would be greatly appreciated
« Last Edit: December 13, 2009, 02:21:23 PM by PPowerHouseK »

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Reading a value from a file, then comparing it?
« Reply #1 on: December 13, 2009, 03:32:48 PM »
This is wrong.

Code: [Select]
set code= <code.ini
You need help with the set command.
Say this:
help set
And read it over.

ghostdog74



    Specialist

    Thanked: 27
    Re: Reading a value from a file, then comparing it?
    « Reply #2 on: December 13, 2009, 06:06:23 PM »
    for reading and parsing ini files, you can use vbscript
    Code: [Select]
    Set objFS=CreateObject("Scripting.FileSystemObject")
    strFile = WScript.Arguments.Item(0)
    WScript.Echo objFS.OpenTextFile(strFile).ReadLine
    usage:
    Code: [Select]
    c:\test> cscript //nologo readline.vbs  myini.ini

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: Reading a value from a file, then comparing it?
    « Reply #3 on: December 13, 2009, 09:02:04 PM »
    Set /p var=<file.ini
    the above will work for you.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    PPowerHouseK

    • Guest
    Re: Reading a value from a file, then comparing it?
    « Reply #4 on: December 19, 2009, 10:19:09 AM »
    Set /p var=<file.ini
    the above will work for you.

    Once again the only useful help posted! You rock helpmeh.

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: Reading a value from a file, then comparing it?
    « Reply #5 on: December 21, 2009, 04:29:52 PM »
    Once again the only useful help posted! You rock helpmeh.
    Thanks. I remember trying to use the set command to get a variable from a file. It was pretty brutal.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.