Dana Posted August 28, 2019 Share Posted August 28, 2019 I don't know if this is an issue with the FileOpenDialog function itself, windows 10, or the helpfile, but: The second parameter for FileOpenDialog is "init dir". If that directory exists, no problem. If that directory doesn't exist, it seems to default to the script directory... at least the first time. If you browse to a different folder, the next time you use the function, the dialog opens in the last directory you used. Even if you exit the program (or SciTE if you're running it from there) and rerun the program, it still goes back to that same directory last used. Is this intended behavior, or something windows 10 is doing? Where is that last directory stored? I couldn't find it in the registry. Interestingly, if the "init dir" directory is then created, the file open dialog will then properly open in that location. To summarize, it looks like FileOpenDialog uses the "init dir" if it exists, the last directory used if "init dir" doesn't exist, and the script directory if there is no last directory used. If that's expected behavior, should it not be in the help file? ConsoleWrite("working directory: " & @WorkingDir & @CRLF) ConsoleWrite("script directory: " & @ScriptDir & @CRLF) While 1 $FilePath = FileOpenDialog("Select Input FIle", @ScriptDir & "\data", "All (*.*)") If @error Then Exit ConsoleWrite("Selected file: " & $FilePath & @CRLF) ConsoleWrite("working directory: " & @WorkingDir & @CRLF) WEnd Link to comment Share on other sites More sharing options...
Jfish Posted August 28, 2019 Share Posted August 28, 2019 (edited) The help file says: Quote @WorkingDir is changed on successful return. I am guessing that is what you are seeing ... ? Edited August 28, 2019 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Dana Posted August 28, 2019 Author Share Posted August 28, 2019 It is indeed using the same directory as @workingdir (which starts out the same as @scriptdir until something changes @workingdir). But when the program (or SciTe) completely exits and I run the script again, @workingdir is again the same as @scriptdir... but it's still looking for the file in the directory used last time the program was run, not the current @workingdir which was reinitialized to @scriptdir when the program restarted. Link to comment Share on other sites More sharing options...
KaFu Posted August 28, 2019 Share Posted August 28, 2019 (edited) I think it defaults to somewhere here if the folder does not exist: \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\ Couldn't find a quick way to decoded those MRUs properly though. I use a custom version of _FileOpenDialog_Ex() to reset @workingdir to the initial script workingdir (because the new workingdir is blocked from deletion). Add a test to initdir there and you're golden. Func _FileOpenDialog_Ex($sTitle, $sInitDir, $sFilter, $iOptions = 0, $sDefaultName = "", $hWnd = 0) #cs https://groups.google.com/forum/?hl=en&fromgroups=#!topic/microsoft.public.vc.mfc/HafQr4gIRY0 The problem is that GetOpenFileName changes the current directory to the last browsed one. The current directory and any of its parents cannot be deleted. #ce Local $sWorkingDir = @WorkingDir if not StringInStr(FileGetAttrib($sInitDir),"D") then $sInitDir = @ScriptDir Local $sFilename = FileOpenDialog($sTitle, $sInitDir, $sFilter, $iOptions, $sDefaultName, $hWnd) Local $iError = @error FileChangeDir($sWorkingDir) Return SetError($iError, 0, $sFilename) EndFunc ;==>_FileOpenDialog_Ex Edited August 29, 2019 by KaFu yutijang and Jfish 2 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Dana Posted August 30, 2019 Author Share Posted August 30, 2019 Thanks... it's not actually a problem, I was just trying to understand what's happening. I'm guessing that Windows takes over if the init dir isn't valid, using the MRU directory if available, and the program or script directory if it isn't, and that Autoit isn't involved in that decision at all if the init dir doesn't exist. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now