|
|
|||||||
Help again, I need to set a variable from an ini file. right now I want to use $rom as variable, ini file name is "stbof.ini". also the path variable I am using to ini file is "$install+" And ini file looks like this; CDPATH=F:\ HDPATH=C:\botf\ CURRENTGAME=0 LANGUAGE=ENGLISH VICTORY=KILLALL INSTALL=MAXIMUM 3D=DIRECT3D TACTICAL=DETAILED SOUNDON=ON I need Variable to be "F:\" "or what ever is in ini" if any one can get me the right script it would be great. thunderchero |
||||||||
|
|
|||||||
You don't show the section header. What is it? |
||||||||
|
|
|||||||
that is all that is in the ini thunderchero |
||||||||
|
|
|||||||
Then IMHO it is not a properly formatted INI. I don't think ReadProfileString() will be able to read it. Is it of your making? Can you not add a header? |
||||||||
|
|
|||||||
It is not of my making it was made in 1999 thunderchero |
||||||||
|
|
|||||||
Ok If I make ini look like this; [settings] CDPATH=F:\ HDPATH=C:\botf\ CURRENTGAME=0 LANGUAGE=ENGLISH VICTORY=KILLALL INSTALL=MAXIMUM 3D=DIRECT3D TACTICAL=DETAILED SOUNDON=ON the next time game starts it removes it so would that work? thunderchero |
||||||||
|
|
|||||||
YOu could add a section header to the INI file and then use ReadProfileString(). Code: Break On $path='C:\' $file='test.ini' $rom=ReadProfileString($path+$file,'header','CDPATH') $rom ? |
||||||||
|
|
|||||||
ReadProfileString() was what I was tring to use But never got it to work now I know why. but please still help me. thunderchero |
||||||||
|
|
|||||||
Alternately, you can use the ReadFile() UDF and Split(). Code: Break On Function ReadFile($file) Dim $lf, $f, $_, $t $lf=chr(10) $f=freefilehandle $_=open($f,$file) if @error exit @error endif do $t=$t+$lf+readline($f) until @error $_=close($f) $ReadFile=split(substr($t,2),$lf) EndFunction $rom='' $path='C:\' $file='test.ini' $romarray=Readfile($path+$file) For $Line = 0 to UBound($romarray) If Split($romarray[$Line],'=')[0]='CDPATH' $rom = Split($romarray[$Line],'=')[1] $Line = UBound($romarray) EndIf Next $rom ? |
||||||||
|
|
|||||||
Hmm- it sounds like the "real" utility that uses this file removes the header. I guess you want to be able to change values in this before you use the real program? If so, try this: Code: Move 'stbof.ini' 'stbof.bak' ; rename original file $ = RedirectOutput('stbof.ini') ; create new file '[Settings]' ? ; add header Display 'stbof.bak' ; add original content to new file $ = RedirectOutput('') ; Close redirection Del 'stbof.bak' ; clean up If you don't need to modify the original content, but simply read it, simplify the above to: Code: $ = RedirectOutput('MYstbof.ini') ; create new file '[Settings]' ? ; add header Display 'stbof.ini' ; add original content to new file $ = RedirectOutput('') ; Close redirection ; read whatever you need from the new, properly formatted INI file $Install = ReadProfileString('MYstbof.ini', 'SETTINGS', 'CDPATH') Del 'MYstbof.ini' ; clean up Glenn |
||||||||
|
|
|||||||
Ummm... you renamed it, remember? Code: Display 'stbof.bak' ; add original content to new file |
||||||||
|
|
|||||||
That's right, I renamed it... Then created a new empty file with the original name. Then added a header line to the new file that was missing in the original. Then took the backed-up file contents and added them to the new file after the header, which is why I'm referencing the .BAK file in the Display command. Remember - the RedirectOutput is still in effect. Thus, the content in the original file name now looks like a valid INI file. Glenn |
||||||||
|
|
|||||||
Ja, but in your simplified version, it no worky unless you have stbof.bak as in the first example. [edit]Nevermind... you surely went back and edited your original post |
||||||||
|
|
|||||||
Huh? The first example is used if you want to modify the orignial and convert it to an INI format, hence the rename and copy of the BAK onto the INI. The second makes a new .INI file in proper format called MYstbof.ini. Since the original wasn't renamed, Display references the original .INI file and not the BAK. G- |
||||||||
|
|
|||||||
I know what the currently posted code does. I should have taken a screenshot *before* you edited. |
||||||||
|
|
|||||||
Les, I got the second one (read file) to work for me. Had to create folder in my install folder and copy the ini into folder so it would read from full path. Thanks thunderchero |