Instead of create a temporary folder, multi-thread, open and close a dummy requester (ugly hack!)...
it's enough to just slightly modify the path string, the first time you open a requester.
For example, change C:\Users\Me\Downloads\ to C:\Users\Me\Downloads\<timestamp>\..\
That is enough to prevent Windows from seeing an identical string and changing your path --- plus, it will open in the folder you really want without having to create that <timestamp> dummy subfolder!
Code: Select all
; Adapt this however you want
Procedure.s _OpenFileRequester(Title.s, DefaultFile.s, Pattern.s, PatternPosition.i, Flags.i = 0)
; Workaround for Windows 7+ behavior: slightly manipulate path the first time you open a requester
Static HasRun.i = #False
If (Not HasRun)
HasRun = #True
If (DefaultFile = "")
DefaultFile = GetCurrentDirectory()
EndIf
DefaultFile = GetPathPart(DefaultFile) + Str(Date()) + "\..\" + GetFilePart(DefaultFile)
MessageRequester("", "!!! Modified the first call's path to:" + #LF$ + DefaultFile)
EndIf
ProcedureReturn OpenFileRequester(Title, DefaultFile, Pattern, PatternPosition, Flags)
EndProcedure
; You can use a macro to override the native function
Macro OpenFileRequester(Title, DefaultFile, Pattern, PatternPosition, Flags = 0)
_OpenFileRequester(Title, DefaultFile, Pattern, PatternPosition, Flags)
EndMacro
CompilerIf (#PB_Compiler_Debugger)
MessageRequester("Instructions",
"1. Compile this to an EXE (Desktop\SomethingUnique.exe)" + #LF$ +
"2. Run it" + #LF$ +
"3. When the first requester opens, choose a file in a DIFFERENT folder" + #LF$ +
"4. The second requester SHOULD open in the original folder (bug fixed!)" + #LF$ +
"5. Run the program again - it SHOULD open in the original folder too")
CompilerElse
ProgramDir.s = GetUserDirectory(#PB_Directory_Downloads)
MessageRequester("", "Should open in:" + #LF$ + ProgramDir)
OpenFileRequester("Title", ProgramDir, "All Files|*.*", 0)
OpenFileRequester("Title", ProgramDir, "All Files|*.*", 0)
CompilerEndIf