mIRC Home    About    Download    Register    News    Help

Print Thread
creating ini files with /writeini problem #137558 14/12/05 12:15 AM
Joined: Nov 2005
Posts: 42
A
Aenei Offline OP
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Nov 2005
Posts: 42
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?

Re: creating ini files with /writeini problem #137559 14/12/05 05:36 AM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
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
}

Last edited by MikeChat; 14/12/05 05:41 AM.
Re: creating ini files with /writeini problem #137560 14/12/05 06:53 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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

Re: creating ini files with /writeini problem #137561 14/12/05 07:12 AM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
$shortfn() returns what you pass it if the file doesn't exist. You're better off using quotes.

Code:
writeini " $+ $scriptdirtestfile.ini" ...

Re: creating ini files with /writeini problem #137562 14/12/05 11:02 AM
Joined: Nov 2005
Posts: 42
A
Aenei Offline OP
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Nov 2005
Posts: 42
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!