Sign in to follow this  
Followers 0
gsbaker

Trouble re-setting Working Directory after FileOpenDialog

4 posts in this topic

In the script segment below (which includes lots of MsgBox to see what is going on) I am trying to reset the working directory after successfully returning the results of a FileOpenDialog.

Case $msg = $button5                            ; Select Index background image
    $setMsg = MsgBox(0,"Test","ScriptDir = " & @ScriptDir & @CRLF & "Working Directory = " & @WorkingDir)
    FileChangeDir(@ScriptDir & "\Resources")
    $select_file = FileOpenDialog("Select Index background image from THIS FOLDER ONLY!", @ScriptDir & "\Resources", "(*.jpg;*.png;*.gif)")
    If $select_file <> "" Then
        $filelength = (@ScriptDir & "\Resources\")
        $scriptlen = StringLen($filelength)
        $filerel = StringTrimLeft($select_file,$scriptlen)
        GUICtrlSetData($Input[70], $filerel)
    EndIf
    $setMsg = MsgBox(0,"Test","ScriptDir = " & @ScriptDir & @CRLF & "Working Directory = " & @WorkingDir)
    FileChangeDir(@ScriptDir)
    $setMsg = MsgBox(0,"Test","ScriptDir = " & @ScriptDir & @CRLF & "Working Directory = " & @WorkingDir)

While the last FileChangeDir statement seems to change the working directory back to where I want it, it does NOT change it for the next time I use FileOpenDialog - which starts in the same place as the directory from the last successful FileOpenDialog. For some reason it is not re-setting the "init dir" parameter, but is using the previous results.

Am I missing something?

Now can I get the FileOpenDialog to start in a specific directory (@ScriptDir) each time, and not pick up the directory from the previous result?

Thanks for your assistance.

Share this post


Link to post
Share on other sites



gsbaker,

I cannot help with your specific problem - it looks as if it should work to me. ;)

However, I found the seemingly random behaviour of the FileOpenDialog dialog so annoying that I actually wrote my own UDF to do what I wanted and not what Windows thought I might want. :idiot:

Take a look at the ChooseFileFolder UDF in my sig. If you really want to limit the user to selecting files from a single folder the UDF will let you do just that - it was one of the things about the FileOpenDialog dialog that annoyed me the most! :)

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

#3 ·  Posted (edited)

Thanks M23. I will have a look. Stupid question? Where should I "unzip" these to?

Also, it looks like this also changes the working directory. Is that correct? Check that - it appears to NOT change the working directory :)

Edited by gsbaker

Share this post


Link to post
Share on other sites

gsbaker,

I would suggest you unzip them into a folder where you normally create your scripts - they all need to be together for the example to work. ;)

If you decide to use them in other scripts then you will need to put the include files (everything except the example) somewhere where AutoIt can find them. I would not suggest putting them in with the AutoIt includes - for a start Vista/Win7 do not like you putting things into the "Program Files" folder!

But you can set specific folders that AutoIt will search for #include files as well as the standard "C:\Program Files\AutoIt3\Include" - from the Help file:

"There is a special registry value that can be created at "HKEY_CURRENT_USER\Software\AutoIt v3\AutoIt" called "Include". It should be a REG_SZ (string) value. The contents of this value are a semi-colon delimited list of directories that should be searched for files when resolving #include's in addition to the standard locations."

If you have the full SciTE4AutoIt3 editor, you can also set this folder in SciTEConfig - look in the <Tools> menu.

So you can put all your downloaded includes into a folder away from "Program Files" - and they will not be overwritten when you next update! And you can call them using the same syntax as the standard include files. :)

this also changes the working directory. Is that correct?

No - it makes no changes to anything at all. It just returns the selected file(s)/folder(s) in a "|" delimited string. :idiot:

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

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  
Followers 0