Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • Moderators
Posted

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

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:

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

 

Posted (edited)

@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
  • Moderators
Posted

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

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:

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

 

Posted

@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.

  • Moderators
Posted

FireFox,

No problem. ;)

DarkB1ade,

All clear? :)

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:

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

 

Posted

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

Posted

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

Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

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
Posted

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...