Sign in to follow this  
Followers 0
GordonFreeman

Force FileOpenDialog to show "init dir" always

7 posts in this topic

The Function FileOpenDialog only show init dir when i not select a file, when i select a file the folder of this file is the init dir. Theres an way to force FileOpenDialog to "respect" always the "Init Dir" parameter?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <Array.au3>
#include <File.au3>


$hGUI = GUICreate("Form1",500,500,-1,-1)

$hBtnGet = GUICtrlCreateButton("Test",400,400,100,25)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hBtnGet
            $File = FileOpenDialog("Selecione um Arquivo",@ScriptDir,"All (*.*)",1)
            FileChangeDir(@ScriptDir)
            MsgBox(0,"",$File)

    EndSwitch
WEnd

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

The initial dir is @scriptdir = D: Then i selected a file in D:Music. When i close and click again the init dir will be D:Music instead of D:. And i can re-run script and will happens the same think

Thanks for attention

Edited by GordonFreeman

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You need to use a fixed path not a macro and it will work.  You can make it a relative path to your script - try that.  Because the successful return changes the @workingdir

 

@WorkingDir is changed on successful return. - the help file

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

Lol. Same code and now working properly. I just put the same code on a script in Desktop works, then i moved to D: and also works. Anyway, thanks.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Form1", 100, 100, -1, -1)
$hBtnGet = GUICtrlCreateButton("Test", 10, 35, 80, 25)
GUISetState(@SW_SHOW)

Global $sInitDir = @ScriptDir

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $hBtnGet

            ; http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx
            ; OPENFILENAME structure
            ; lpstrInitialDir
            ; Windows 7: If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory.

            If StringRight($sInitDir, 1) = "\" Then
                $sInitDir = StringTrimRight($sInitDir, 1)
            Else
                $sInitDir &= "\"
            EndIf
            ConsoleWrite($sInitDir & @CRLF)

            $File = FileOpenDialog("Selecione um Arquivo", $sInitDir, "All (*.*)", 1)
            
            MsgBox(0, "", $File)
            
    EndSwitch
WEnd
Edited by KaFu

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