Setting DefaultFile$ with SaveFileRequester() /OpenFileRequester() (Win10) - possible bug
Posted: Sun Dec 19, 2021 8:36 am
Suppose you wish to restrict the user of your application to save their work files in their standard windows documents folder and nowhere else. According to the PB manual "The DefaultFile$ is useful to initialize the requester in the right directory and with the right filename.", so you might code something like this:
Now, if you run this code in the PB IDE, it works as expected. However, if you compile this code as a standalone exe and run it, then, if you change the directory, SaveFileRequester() does not return to the default "documents" directory as required. In fact, if you then re-run the exe, it launches with the changed directory.
Can anyone shed some light on this odd behavior? or is it a bug? or am I doing something wrong? Could Windows be somehow associating the last accessed directory with that exe file and overriding the default?
The same behavior occurs with OpenFileRequester().
Test environment: Windows 10 Pro, x64, PB5.73
Code: Select all
Dir$ = GetHomeDirectory() + "Documents\" ; set default directory
DefaultFile$ = Dir$ + "MyFile.txt" ; set default file
Pattern$ = "Text (*.txt)|*.txt"
Repeat
File$ = SaveFileRequester("Save", DefaultFile$, Pattern$, 0)
If File$ <> "" And GetPathPart(File$) <> Dir$
MessageRequester("Error", "Please do not change directory.")
EndIf
Until File$ = "" Or GetPathPart(File$) = Dir$ ; exit if user cancels or directory unchanged
Can anyone shed some light on this odd behavior? or is it a bug? or am I doing something wrong? Could Windows be somehow associating the last accessed directory with that exe file and overriding the default?
The same behavior occurs with OpenFileRequester().
Test environment: Windows 10 Pro, x64, PB5.73