Jump to content

Recommended Posts

Posted (edited)

Hello.

Here's the code.

$pathToConfig = IniRead("settings.ini", "General", "PathToConfig", "")
If  Not FileExists($pathToConfig) Then
    TrayTip("Script", "Please point me to config file.", 5)
    $newPath = FileOpenDialog("Script", @ScriptDir, "Config files (*.cfg)", 1)
    IniWrite("settings.ini", "General", "PathToConfig", $newPath)
    $pathToConfig = $newPath
EndIf

So IniWrite with $newPath gets ignored for some reason. It returns 1, which means success, but still strange.

I tried using some random strings instead of $newPath, for example "test1235", but still no success.

But the most interesting thing is that IniWrite works when used before IniRead. That is, it gets updated both in NP++ and via the code.

Additional info:

  • I have 3 more IniReads above $pathToConfig line;
  • Sometimes the value just doesn't change in .ini file, and sometimes (1 case of like 10) it becomes blank (when used after IniRead).

Would appreciate any help.

Edited by Helixanon
Posted

Yup, .ini doesn't get updated although IniWrite returns 1. I suppose the .ini file may be busy by IniRead or something? I tried to look for any command to release the .ini file handle (like File.Close()), but there seems to be none.

Posted

Oh wow wait. I actually didn't notice the "\" sign you've put. I typed it and for some reason it did, indeed, update the file.

So uhm, why was it needed to insert the scriptDir and put the backslash? Shouldn't it be working with non-absolute path?

Anyway, the issue is solved, and I thank you.

Posted (edited)

Well the .ini file is in the same folder as the script itself.

Why did IniRead work this way? What exactly caused Write not to work?

I'm just curious, bare with me :)

Edited by Helixanon
Posted

There is nothing apparent which should cause that code to not work, especially if it returns 1, and is why I suspect there is more code at play since the code supplied does not test it.

But perhaps the help file is wrong and it does require full path.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

The post #1 code worked here as is.

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

  • Moderators
Posted

Helixanon,

I think the reason behind the problem lies in this section of the Help file (my bold):

  Quote

The working directory is set to @ScriptDir at script start and this path can be altered during the running of the script by calling FileChangeDir. But note that the current working directory can be also be changed automatically by some functions - e.g. FileOpen/SaveDialog on a successful return,

Expand  

So after a successful selection of the new path, the working directory is reset to the selected folder and so you need to specify the full path of the ini file - or reset the working folder to @ScriptDir using FileChangeDir.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

Ooooh, that's interesting. So as summary, after FileOpenDialog it tried to look for .ini file in the folder which was returned by FileOpenDialog? Funny stuff. Right, should've mentioned that the .ini file was in a same folder but I thought it was obvious :)

Thank you.

Edited by Helixanon

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
  • Recently Browsing   0 members

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