mIRC Homepage
Posted By: Aenei creating ini files with /writeini problem - 14/12/05 12:15 AM
Hey, not sure if I am asking something that has been dealt with before. If I am then I apologise for wasting everyone's time, but I couldn't find quite what my problem is searching through past posts.

basically I am trying to write to an ini file in a script, and a command along the lines of

Code:
/writeini testfile.ini Section Variable Value


produces an entry along the lines of

Code:
[Section]
Variable=Value


as we would expect.
I, being a keen little so-and-so wanted to be a bit cleverer and so am using something like

Code:
/writeini $shortfn($scriptdir\testfile.ini) Section2 Variable2 Value2


so that it can be called from wherever the script ends up. Of course this isn't totally correct and I properly should use

Code:
/writeini $shortfn($scriptdirtestfile.ini) 


...etc but I just feel unhappy without that extra backslash.

All is well until I (don't ask me why, I don't know) tried to run the script without an existing ini file to write to at which point everything has gone to hell. When I do this, the line shown above generates a file C:\Program

containing

Code:
[Files\mIRC\\testfile.ini]
Section2=Variable2 Value2


This is a bit unhelpful, and yes I know that so long as my ini file exists then I can happily carry on accessing it as I am. But liking to design for other eventualities as I do this is a bit unsatisfactory.

So, can I make mirc generate an ini file where I want it if it doesn't already exist, and if so, how?
as a test you might try this out
Code:
alias testmake {
  if (!$exists($mircdirtestfolder)) { mkdir testfolder }
  if (!$exists(testfolder\testfile.ini)) { write -c testfolder\testfile.ini }
  writeini testfolder\testfile.ini Section Variable Value
}
I believe the problem is that you need to surround the ini filename in quotes ("). The location of your mIRC means that there is a space (\Program Files\). The writeini interprets that space as meaning you are entering the next argument (the section name). Try this:

writeini $+(",$scriptdir,testfile.ini,") Section2 Variable2 Value2

-genius_at_work
Posted By: hixxy Re: creating ini files with /writeini problem - 14/12/05 07:12 AM
$shortfn() returns what you pass it if the file doesn't exist. You're better off using quotes.

Code:
writeini " $+ $scriptdirtestfile.ini" ...
Posted By: Aenei Re: creating ini files with /writeini problem - 14/12/05 11:02 AM
Quote:
as a test you might try this out


Yes, your snippet works fine, creates the folder and ini file with no problems at all. I shall keep it handy, I think it might come in useful soon.

genius_at_work you are aptly named, and thanks also hixxy. The quotes method works fine, creating the ini if it doesn't exist. I'm going with the quotes method for the moment as its slightly simpler, and also will handle things if for some reason the ini disappears halfway through execution.

Thanks very much guys!
© mIRC Discussion Forums