Fileread dropping colon from filename
I have an INI file containing
[C:\ET\]
DATA=c:\encore\userdata\
I need to get the [C:\ET\] so have been using FileRead but it returns [C\ET\]
Any ideas why or how I get round it?
Thanks
Matt
Archive: Fileread dropping colon from filename
Fileread dropping colon from filename
I have an INI file containing
[C:\ET\]
DATA=c:\encore\userdata\
I need to get the [C:\ET\] so have been using FileRead but it returns [C\ET\]
Any ideas why or how I get round it?
Thanks
Matt
4.9.2.10 ReadINIStr
user_var(output) ini_filename section_name entry_name
Reads from entry_name in [section_name] of ini_filename and stores the value into user variable $x. The error flag will be set and $x will be assigned to an empty string if the entry is not found.
Straight from the documentation.....
Oh you want the section name....hmmmmm Try FileReadByte
So this is a bug in NSIS ?
How do I convert the integer from FileReadByte to character. I can't find the equivalent of CHR() in the documentation!
IntFmt $0 "%c" $1
where $1 is the output of FileReadByte and you'll get the character read in $0. It's up to you to find out how to skip the non text part of the file, FileReadByte will read anything.
I wrote the following script to do this but there are still problems. I think the colon must have some special effect that I am not aware of because the code reads [C:\ET\] as C:ET\ i.e. missing the first slash. here's the code
;Get Section name from MyINI.ini
Strcpy $INSTDIR ""
FileOpen $FileHandle "$WinDir\MyINI.ini" "r"
start:
FileReadByte $FileHandle $1
IntFmt $0 "%c" $1
StrCmp $0 "[" start
StrCmp $0 "]" fileclose
MessageBox MB_ICONQUESTION|MB_OK "New value $0 Old Value $InstDir"
strcpy $INSTDIR "$INSTDIR$0"
goto start
fileclose:
FileClose $FileHandle
Using the messagebox I can see that it reads in all the characters but drops the first slash when copying to $INSTDIR
Appears that NSIS checks $INSTDIR for a correct value and removes the back-slash after the dir. Probably NSIS doesn't handle correctly folders with back-slash at the string end, so instead of fixing it, the author used this to solve the problem. You can fix it just by replacing $INSTDIR by another variable.
I have resolved this. $INSTDIR seems to be automatically validated as you write to it hence strange behaviour. If you write to another variable such $0 all my problems go away. So now I FileRead to $0, strip [] from section name and then save results to $INSTDIR
Sorted! Thanks for your help
Matt
Thanks Deguix, I replied before refreshing the postings so didn't see your posting!!