Jump to content

How to read variables from a textfile without including?


Recommended Posts

Hey peoples,

I want to declare some variables in an external textfile which has to be read from my compiled script.

The background is that I want to write a script for a simple file backup for our customers. Because from machine to machine the install dirs are different I want my customers to insert the dirs into a textfile where all variables I need in my script are declared.

After some testing I now know that my textfile will be completely inserted into the exe-file after compiling and because of this it's not possible to edit the variables after compiling my script.

Is there a possibility to include an external file to my script but only the way that the compiled one will use the textfile itself instead of include it into my script?

Thanks in advance.

Dennis

Link to comment
Share on other sites

Help file helps

;check help for filewrite,fileread,fileopen

$file = FileOpen(@ScriptDir & "\test.txt", 0)


If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

    $chars = FileRead($file, 1)
    FileClose($file)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Txt file contains: ", $chars);$chars is you variable from file

While 1
Sleep(100)
Wend
[Cheeky]Comment[/Cheeky]
Link to comment
Share on other sites

Look into ini files and iniread.

make a file called "values.ini"

[programs]
Office=C:\Program Files\Microsoft Office
Firefox=C:\Program Files\Mozilla Firefox

Then in your program

$Officelocation=iniread("values.ini","programs","Office","")
$Firefoxlocation=iniread("values.ini","programs","Firefox","")

You can also use inireadSection if you wanted, but this may be easier.

Link to comment
Share on other sites

Ok thanks a lot for the information.

@lordicast: I was searching in the helpfile but didn't know the keyword "fileopen".

Edit:

iniread works great, thank you!

Edited by Jass
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...