# Function Reference

# FileSaveDialog

Initiates a Save File Dialog.

FileSaveDialog ( "title", "init dir", "filter" [, options = 0 [, "default name" [, hwnd]]] )

## Parameters

title | Title text of the Dialog GUI.
init dir | Initial directory selected in the GUI file tree.
filter | File type single filter such as "All (*.*)" or "Text files (*.txt)" or multiple filter groups such as "All (*.*)|Text files (*.txt)" (See Remarks).
options | [optional] Dialog Options: To use more than one option, BitOR the required values together. $FD_PATHMUSTEXIST (2) = Path Must Exist (if user types a path, ending with a backslash) $FD_PROMPTOVERWRITE (16) = Prompt to OverWrite File Constants are defined in FileConstants.au3.
default name | [optional] File name to suggest to the user to save the file with. Default is blank ("").
hwnd | [optional] The window handle to use as the parent for this dialog.

## Return Value

Success: | the full path of the file chosen. Results for multiple selections are "Directory|file1|file2|..."
Failure: | sets the @error flag to non-zero.
@error: | 1 = File selection failed. 2 = Bad file filter

## Remarks

Separate the file filters with a semicolon as shown in the example.
Multiple groups of filters are separated by a pipe "|".
If default name is given, options must also be given. If none of the options are wanted, use 0 for options.
Special Windows folders (such as "My Documents") can be set as root by using the right CLSID detailed in the Appendix.
@WorkingDir is changed on successful return.

## Related

FileOpenDialog, FileSelectFolder

## Example

    #include <FileConstants.au3>
    #include <MsgBoxConstants.au3>
    #include <StringConstants.au3>

    Example()

    Func Example()
        ; Create a constant variable in Local scope of the message to display in FileSaveDialog.
        Local Const $sMessage = "Choose a filename."

        ; Display a save dialog to select a file.
        Local $sFileSaveDialog = FileSaveDialog($sMessage, "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Scripts (*.au3)", $FD_PATHMUSTEXIST)
        If @error Then
            ; Display the error message.
            MsgBox($MB_SYSTEMMODAL, "", "No file was saved.")
        Else
            ; Retrieve the filename from the filepath e.g. Example.au3.
            Local $sFileName = StringTrimLeft($sFileSaveDialog, StringInStr($sFileSaveDialog, "\", $STR_NOCASESENSEBASIC, -1))

            ; Check if the extension .au3 is appended to the end of the filename.
            Local $iExtension = StringInStr($sFileName, ".", $STR_NOCASESENSEBASIC)

            ; If a period (dot) is found then check whether or not the extension is equal to .au3.
            If $iExtension Then
                ; If the extension isn't equal to .au3 then append to the end of the filepath.
                If Not (StringTrimLeft($sFileName, $iExtension - 1) = ".au3") Then $sFileSaveDialog &= ".au3"
            Else
                ; If no period (dot) was found then append to the end of the file.
                $sFileSaveDialog &= ".au3"
            EndIf

            ; Display the saved file.
            MsgBox($MB_SYSTEMMODAL, "", "You saved the following file:" & @CRLF & $sFileSaveDialog)
        EndIf
    EndFunc   ;==>Example