Jump to content
Sign in to follow this  
Kerros

Possible Bug in IniWriteSection

Recommended Posts

Kerros

I'm posting this here first as there is a workaround for the issue, but it still seems like it would be a bug.

IniWriteSection will not create a folder when creating a new Ini file. If you manually create the folder IniWriteSection will create the file in the newly created folder.

CODE
Dim $aData2[3][2] = [ [ "FirstKey", "FirstValue" ], [ "SecondKey", "SecondValue" ], [ "ThirdKey", "ThirdValue" ] ]

$sIni = @DesktopDir & "\test.ini"

$return1 = IniWriteSection($sIni,"SectionA",$adata2,0);<---Creates file correctly

ConsoleWrite("DesktopDir: "&$return1&@error&@CRLF)

$sIni2 = @DesktopDir & "\temp\test2.ini"

$return2 = IniWriteSection($sIni2,"SectionB",$adata2,0);<---Does not create directory and file

ConsoleWrite("DesktopDir and another folder: "&$return2&@error&@CRLF)

DirCreate( @DesktopDir&"\temp");Manually create directory

$return3 = IniWriteSection($sIni2,"SectionB",$adata2,0);<---Creates file

ConsoleWrite("DesktopDir and another folder after manually creating folder: "&$return3&@error&@CRLF)

Any Ideas or does this need to be moved to the Bug Report Forum?

Thanks,

Kerros


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
Nahuel

And why would this be a bug? <_<

It doesn't say anywhere that if the directory doesn't exist it is created.

If file does not exist, it is created. Keys and/or sections are added to the end and are not sorted in any way.

Share this post


Link to post
Share on other sites
Kerros

Ok, maybe not so much a bug as a feature request then. While the documentation does state that file will be create, it was my assumption that the path would also be created as well, as you can't create a file without the folder being there. A change in the documentation would also be helpful.

If file does not exist, it is created, if the path already exists. Keys and/or sections are added to the end and are not sorted in any way.

This may just be a suggestion then, if something similar to the flags for filecopy or filemove

flag [optional] this flag determines whether to overwrite files if they already exist:

Can be a combination of the following:

0 = (default) do not overwrite existing files

1 = overwrite existing files

8 = Create destination directory structure if it doesn't exist (See Remarks).

Edited by Kerros

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
SmOke_N

The Ini* functions use standard Microsoft functions currently, if you feel this to be a bug, you'll need to report the issue with them.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Kerros

I posted about this being a possible bug because the function didn't work as I had expected it to. Upon finding out that it's not a bug, but this is how it's designed, I posted a suggestion. If there are more important features or things that need to be worked on for the functionality of AutoIt that is fine, and this suggestion can be ignored. I now know how it works and will be able to apply that.


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Share this post


Link to post
Share on other sites
SmOke_N

I posted about this being a possible bug because the function didn't work as I had expected it to. Upon finding out that it's not a bug, but this is how it's designed, I posted a suggestion. If there are more important features or things that need to be worked on for the functionality of AutoIt that is fine, and this suggestion can be ignored. I now know how it works and will be able to apply that.

Ini questions have been popping up quite a bit lately... You could write a simple/quick wrapper for it I'm sure... Something like:
Func _IniWriteSection($sFileName, $sSection, $sData, $iIndex = 1)
    If FileExists($sFileName) = 0 Then FileClose(FileOpen($sFileName, 10))
    Return IniWriteSection($sFileName, $sSection, $sData, $iIndex)
EndFunc
Maybe...

I'm not sure, but by the sound of it, it "looked" like Valik may end up re-writing the Ini functions natively... which may change somethings.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Kerros

Thank you SmOke_N that wrapper worked well, I just changed $index = 1 to $index to make it more universal for my script.

Kerros


Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.