Q: FileSelect dialog: How to auto-add the extension to a name to Save?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Q: FileSelect dialog: How to auto-add the extension to a name to Save?

24 Jan 2023, 14:10

Hi all,

I want to use the FileSelect dialog to enter a file name under which to save a file.
I also want to use Option 16: "Prompt to Overwrite File".

I had hoped that if I specify a Filter parameter with one extension (e.g. "*.txt"), that that extension then is automatically added to any file name that I enter into the dialog. Alas, it seems this is not the case.

Thus, when a file "test.txt" already exists and I enter a file name without extension into the dialog, e.g. "test", I get NO overwrite promt, even if an extension Filter "*.txt" is set.

Now, any smart alecks will respond that the help does not say it would, and that it only says that the filter affects the *display* of existing files, and not the entered file name, yada, yada, ...

However, there SHOULD be an option that automatically ensures that the filtered extension is the extension of the entered file name and that if "test.txt" already exists and option 16 is set, that the prompt also comes when only "test" ist entered. It is just too stupid to have to MANUALLY enter the extension if a filter is given.

So, maybe I overlooked something. Therefore the question:
How can I auto-add the extension to an entered name in a Save FileSelect dialog?

Of course I can check the path returned by FileSelect, and check for myself against already existing files, but then I would have to write my own Overwrite Prompt which for sure would look different from the embedded option one and, even worse, it would only pop-up after the FileSelect dialog is already closed - way too late, horrible! Or is there a trick that I don't see so far?

MTIA and regards, a.
RussF
Posts: 1290
Joined: 05 Aug 2021, 06:36

Re: Q: FileSelect dialog: How to auto-add the extension to a name to Save?

24 Jan 2023, 15:12

Try this for AHK V1 (I'm still learning V2).

Code: Select all

SetTimer, HomeCursor, -500
FileSelectFile, test, S16, C:\YourStartingFolder\ .txt, My Save Dialog, Text Files (*.txt)
MsgBox % test
Return

HomeCursor:
    Send {Home}
Return
Russ
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Q: FileSelect dialog: How to auto-add the extension to a name to Save?

24 Jan 2023, 15:40

Thank you, Russ, for brainstorming.

As far as I understand you are giving the user a helpful hand in prefilling the Edit box with the desired extension and then putting the caret in front of it. Ok, that of course is a bit better than nothing. However, I would like to be on the most safe side and also catch the case if the user did delete or overwrite the extension. Still, good brainstorming. Thank you!
RussF
Posts: 1290
Joined: 05 Aug 2021, 06:36

Re: Q: FileSelect dialog: How to auto-add the extension to a name to Save?

24 Jan 2023, 16:05

It all depends on how far you want to go with error checking. In my experience, 10% of any program is actually functional while 90% is written to try and protect the users from themselves. The more error checking time you put in up front, the less troubleshooting you will have to do later.

Russ
autocart
Posts: 214
Joined: 12 May 2014, 07:42

Re: Q: FileSelect dialog: How to auto-add the extension to a name to Save?

24 Jan 2023, 16:08

Thank you, that's exactly my point. :thumbup: I want the dialog to be as fool-proof as possible.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 85 guests