Helixanon

IniWrite gets ignored

15 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

Same result. Returns 1 and .ini didn't get updated.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#8 ·  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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

The post #1 code worked here as is.


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

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,

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Ah yes, thanks Melba, you refresh my memory... I remember now this behaviour with FileOpenDialog and FileSaveDialog.
I had the answer but not the explaination...

Edited by jguinch

Share this post


Link to post
Share on other sites

#14 ·  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

Share this post


Link to post
Share on other sites

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