AskFileName

Returns the filename with its path as selected by a FileOpen dialog box.

Syntax:

AskFileName( title, directory, filetypes, default filename, flag )

Parameters:

(s) title: title of the file name select box.

(s) directory: initial drive and directory.

(s) filetypes: file type selection definition (see below) text highlighted in the File Name field of the Open/Save dialog box or file filter. Note: The "|" is required to separate the descriptive phrase from the mask. It does not mean"or".

(s) default: filename default filename or mask.

(i) flag: see below.

Returns:

(s) string: A string containing the filename and path.

 

This function is the equivalent of a standard Common Dialog FileOpen or a FileSave dialog box. The initial drive and directory is logged, and either a FileSave or a FileOpen dialog box is presented to the user. The default filename or mask is filled in, as well as a selection of filetypes.

The user can either type in a filename or select one via the file list box. File types displayed may be selected from a "File Type" drop down list box. The File Type contents in the drop down list box is specified by the filetypes parameter. The filetype parameter is defined as follows:

 

 filetypes := Description|Mask| [ Description|Mask| ...]

 Description := Any human readable string

 Mask := filespec [; filespec ...]

 filespec := DOS File wildcard mask

 

Basically, a description - visible to the user in the drop down list box, followed by the vertical bar symbol(|), followed by a file mask - for the computer, followed by another vertical bar. This description may be repeated for each desired file type selection.

The filetype parameter field must be enclosed in quotes "". No additional quotes are needed inside these. You can use several descriptions and file type masks. For only one file type, a second "|" is optional. Spaces and alphanumeric characters can be used in file type descriptions. An example is: Text files|*.txt|WinBatch|*.wbt" Several file type masks can be used for a single description. Separate them with a semicolon. An example of this: "Batch files|*.wbt;*.bat;*.cmd".

Flags

Value

Meaning

0

Save style

1

Open style

2

Open style, allowing multiple files to be selected. **

3

Save style, with no "Replace" confirmation.

100

[Vista and newer]  Save style *

101

[Vista and newer] Open style *

102

[Vista and newer] Open style, allowing multiple files to be selected.*

103

[Vista and newer] Save style, with no "Replace" confirmation.*

 

* Vista/Windows 7 or newer : The new dialog style can be invoked by adding 100 to the values passed in the function's 'flag' parameter.  Each of the four values 100, 101, 102 and 103 otherwise have the same effect as the corresponding 0, 1, 2, and 3 values. If one of the 100-plus values is used on a system running a version of Windows predating Vista, the added 100 is ignored and the function reverts to the older common file dialog style.

** If the "flag" specified is 2  (Open Style, allowing multiple files to be selected), the selected files will be returned as a delimited list. The combined file names (not including the file paths)  selected cannot exceed 2048 characters, otherwise the AskFileName dialog will be re-displayed. In other words, the number of files that can be selected is limited. Do not use flag 2 to select multiple files, if the potential number of files to be selected, could exceed this maximum. Flag 102 does not have this limitation.

Note: AskFileName changes the current working directory to that of the selected file.

 

Example:


types="All Files|*.*|WIL Files|*.wbt;*.mnu|Text Files|*.txt|"
fn1=AskFilename("SelectFile", "C:\WinBatch", types, "Sol.wbt", 1)
Message("File selected was", fn1)

which produces:

wila-k1_shg.gif

and then:

wila-k2_shg.gif

See Also:

AskFileText, AskItemList, AskLine