Jump to content
Sign in to follow this  
DarkB1ade

Writing path to ini file issue

Recommended Posts

DarkB1ade

I`m trying to make a larger script which involves asking the user to input a path and saving it to an ini file. In another part of the script i am asking for other information (delivered through a Inputbox) and it works without problem. Also the open file dialg works since writing the path to a file (not ini, but .txt) works flawlessly.

Here is my code

Local $message = "Select your executable"
Local $file = FileOpen("path.txt", 1)
; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
Local $path = FileOpenDialog($message, "C:" & "", "Select the executable (*.exe)", 1 + 4)
If @error Then
MsgBox(4096, "", "No File(s) chosen")
Else
$path = StringReplace($path, "|", @CRLF)
MsgBox(4096, "", "You chose " & $path)
IniWrite("appini.ini", "details", "$path", $path)
FileWrite($file, $path)
EndIf

As u can see the FileWrite works great, but the Iniwrite does nothing

Any assistance will be greatly apriciated

Edited by DarkB1ade

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

I just tried this little reproducer and it works fine:

$path = "C:temptest file1.xls" & @CRLF & "C:temptest file2.xls"
Global $iResult = IniWrite("appini.ini", "details", "$path", $path)
ConsoleWrite($iResult & " " & @error & @LF)
But IniRead can't handle multiline values. You have to save the files the user selected with the "|" character. Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Melba23

DarkB1ade,

The problem is that, as it explains in the Help file for FileOpenDialog:

"@WorkingDir is changed on successful return"

So you are trying to create the ini file in the same folder as the file you select. ;)

Just use FileChangeDir to change it back (to @ScriptDir perhaps?) before you write the ini file. :)

M23

  • Like 1

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
FireFox

@Melba23

So tell me why if you change this :

Local $path = FileOpenDialog($message, "C:\", "Select the executable (*.exe)", 1 + 4)

to this :

Local $path = FileOpenDialog($message, "C:\", "Images (*.jpg;*.bmp)", 1 + 4)

It works...

Edit : Forget, I was choosing the Image in the same folder as the script :>

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Melba23

FireFox,

Your "fix" does not for work for me. :(

If I select a file using FileOpenDialog the @WorkingDir is always changed to the folder of the selected file - regardless of the type of file chosen. Then any non-path-specified file is saved in that folder - until @WorkingDir is changed again.

Are you actually selecting one of the image files when you run that code? Because if you merely cancel the dialog, @WorkingDir is not changed. :)

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
FireFox

@Melba23

Yes, I edited my post to tell that I was wrong.

I was testing the script on my desktop and I was selecting shortcuts (on the desktop) that linked to exes, so I was confused about the directory when choosing images on the desktop.

Thanks anyway for the tip, I did not know that.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
Melba23

FireFox,

No problem. ;)

DarkB1ade,

All clear? :)

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
DarkB1ade

Yes, thank you very much for the quick answers. That did the trick Melba23. I was actually deep in thought about another part of the script and didn`t realise i already had 4 answers:)

Thanks again for the promptness

Share this post


Link to post
Share on other sites
DarkB1ade

I`m not sure i was clear enough, so for other people in the future having this problem, the fix is this:

IniWrite(@scriptDir & "appini.ini", "details", "$path", $path)

@water, my problem wasn`t multiple files selected. I only ever need 1 to be selected. But thanks for the warm welcome guys

Share this post


Link to post
Share on other sites
water

But your code allows "MultiSelect" and handles the pipe character "|". To remove "MultiSelect" remove the "+ 4" in the FileOpenDialog statement.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
DarkB1ade

Ah, sorry for the tripple post, but it seems i can`t edit my own posts. I realised i needed to write some other things to the same ini file later on so instead of mentioning the path every time i just took your advice and changed the working dir back to the script dir

FileChangeDir (@Scriptdir)

Thanks again

@water thanks for the heads up i copied that part from an older script didn`t realise i let the multiselect part live. Fixed

Edited by DarkB1ade

Share this post


Link to post
Share on other sites
water

IIRC you have to have at least a post count of 5 before you can edit a post.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  

×