MAXScript Tools and Interaction with 3ds Max > File Access > External Files Access >

# Standard Open and Save File Dialogs

The following methods display the standard 3ds Max file open, file save, or folder selection browser dialog:

    getOpenFileName [	caption:<title> ] \
    [	filename:<seed_filename_string> ] \
    [	types:<description1>|<pattern1>|<description2>|<pattern2>|...| ] \
    [	historyCategory:<string> ]

    getSaveFileName [ caption:<title> ] \
    [ filename:<seed_filename_string> ] \
    [ types:<description1>|<pattern1>|<description2>|<pattern2>|...| ] \
    [ historyCategory:<string> ]

Both functions return a fully-specified file path name or undefined if the user cancels out.

When the optional keyword filename: is supplied, the string is used to define the path and file name of the file to be loaded or saved. The dialog automatically navigates to the specified path (if available on the disk/network), displays its content in the browsing area and suggests the file name in the "File name" field. If the path does not exist, the current path is used and only the file name is displayed as requested.

FOR EXAMPLE
    f = getOpenFileName caption:"Open A Test File:" \
    filename:"c:/test/test.txt"
    --if the path exists, will result in something like:

The types: parameter lets you specify custom file types and suffixes for the file type drop-down list in the open and save dialogs. You supply a string for this argument that is formatted in a special way, as follows:

    "<description1>|<pattern1>|<description2>|<pattern2>|...|"

In other words, a sequence of file type descriptions and file type patterns each separated by a '|' vertical bar and terminated by a '|' vertical bar.

FOR EXAMPLE
    f = getOpenFileName \
    types:"Data(*.dat)|*.dat|Excel(*.csv)|*.csv|All|*.*|"
Specifies three types in the file type drop-down list, the first reading "Data(*.dat)" and matching *.dat and the second reading "Excel(*.csv)" and matching *.csv and the third reading "All" and matching any file.

The getSaveFileName() function tests for the pre-existence of the file with the chosen file type suffix added.

The history dropdown list in the file load and save dialogs keeps track of previously selected files according to a specified history name. It is available since 3ds Max 2008.

If historyCategory: is not specified, the caption text is used if specified, and if no caption is specified, the default category "MAXScriptFileOpenSave" is used instead.

FOR EXAMPLE
    filename = getOpenFileName \
    caption:"Render To Texture Object Presets Open" \
    filename:(getDir #renderPresets + @"\") \
    types:"Object Preset(*.rtp)|*.rtp" \
    historyCategory:"RTTObjectPresets"

By using the same historyCategory: name for a pair of open and save dialogs, users will see a consistent history dropdown in the dialogs.

    getSavePath [ caption:<window_caption_string> ] [ initialDir:<pathname> ]

This function displays a folder selection browser for the user to select a folder. Returns a string path name for the selected folder or the value undefined if the user presses Cancel in the folder browser.

If the initialDir: keyword argument is specified, the Browse For Folder dialog will be opened at the specified directory. Symbolic pathnames are acceptable as the pathname. Available in 3ds Max 8 and higher.

FOR EXAMPLE,
    getSavePath caption:"my title" initialDir:"$scripts"
    getSavePath caption:"my title" initialDir:(getDir #maxroot)

#### See Also

- Filestream Values

- External File Methods

- File Name Parsing