GetFileOpenName PowerScript function
Description
Displays the system’s Open File dialog box and allows
the user to select a file or enter a file name.
Syntax
|
1 |
<span>GetFileOpenName </span>( <span>title</span>, <span>pathname</span>, <span>filename </span>{, <span>extension </span>{, <span>filter</span> { , <span>initdir</span> { , <span>aFlag</span> } } } } ) |
|
1 |
<span><span></span>GetFileOpenName </span>( <span>title</span>, <span>pathname</span>, <span>filename[ ] </span>{, <span>extension </span>{, <span>filter</span> { , <span>initdir</span> { , <span>aFlag</span> } } } } ) |
|
Argument |
Description |
||||||
|---|---|---|---|---|---|---|---|
|
title |
A string whose value is the title of |
||||||
|
pathname |
A string variable in which you want to |
||||||
|
filename, filename[ ] |
A string variable in which the returned |
||||||
|
extension (optional) |
A string whose value is a 1- to 3-character |
||||||
|
filter (optional) |
A string whose value is a text description
To specify multiple filter patterns for a single display string,
The default is:
|
||||||
|
initdir (optional) |
A string whose value is the initial directory |
||||||
|
aFlag (optional) |
An unsigned long whose value determines |
Return Values
Integer. Returns 1 if it succeeds, 0
if the user clicks the Cancel button or Windows cancels the display,
and -1 if an error occurs. If any argument’s value is null, GetFileOpenName returns null.
Usage
If you specify a DOS-style file extension and the user enters
a file name with no extension, PowerBuilder appends the default
extension to the file name. If you specify a file mask to act as
a filter, PowerBuilder displays only files that match the mask.
If you specify a string for the filename argument,
the user can select only one file. The pathname argument
contains the path name and the file name, for example C: emp est.txt.
If you specify a string array for the filename argument,
the user can select more than one file. If the user selects multiple
files, the pathname argument contains the path
only, for example C: emp. If the
user selects a single file, its name is appended to the pathname argument,
for example C: emp est.txt.
You use the filter argument to limit
the types of files displayed in the list box and to let the user
know what those limits are. For example, to display the description
Text Files (*.TXT) and only files
with the extension .TXT, specify the following
for filter:
|
1 |
"Text Files (*.TXT),*.TXT" |
To specify more than one file extension in filter,
enter multiple descriptions and extension combinations and separate
them with commas. For example:
|
1 |
"PIF files, *.PIF, Batch files, *.BAT" |
The dialog boxes presented by GetFileOpenName and GetFileSaveName are system
dialog boxes. They provide standard system behavior, including control over
the current directory. When users change the drive, directory, or
folder in the dialog box, they change the current directory or folder.
The newly selected directory or folder becomes the default for file
operations until they exit the application, unless the optional initdir argument
is passed.
The aFlag argument is used to pass one
or more options that determine the appearance of the dialog box.
For each option, the value of the flag is 2^(index -1),
where index is an integer associated with each
option as shown in the following table. You can pass multiple options
by passing an aggregate flag, calculated by adding the values of
the individual flags.
If you do not pass an aFlag, the Explorer-style
open file dialog box is used. If you do pass a flag, the old-style
dialog box is used by default. Some options do not apply when the
Explorer-style dialog box is used. For those that do apply, add
the option value for using the Explorer-style dialog box (2) to
the value of the option if you want to display an Explorer-style
dialog box.
For example, passing the flag 32768 (2^15) to the GetFileSaveName function opens
the old-style dialog box with the Read Only check box selected by default.
Passing the flag 32770 opens the Explorer-style dialog box with
the Read Only check box selected by default.
|
Index |
Constant name |
Description |
|---|---|---|
|
1 |
OFN_CREATEPROMPT |
If the specified file does not exist, |
|
2 |
OFN_EXPLORER |
Use an Explorer-style dialog box. |
|
3 |
OFN_EXTENSIONDIFFERENT |
The file extension entered differed from |
|
4 |
OFN_FILEMUSTEXIST |
Only the names of existing files can |
|
5 |
OFN_HIDEREADONLY |
Hide the Read Only check box. |
|
6 |
OFN_LONGNAMES |
Use long file names. Ignored for Explorer-style |
|
7 |
OFN_NOCHANGEDIR |
Restore the current directory to its |
|
8 |
OFN_NODEREFERENCELINKS |
Return the path and file name of the |
|
9 |
OFN_NOLONGNAMES |
Use short file names (8.3 format). Ignored |
|
10 |
OFN_NONETWORKBUTTON |
Hide the Network button. Ignored for |
|
11 |
OFN_NOREADONLYRETURN |
The file returned is not read only and |
|
12 |
OFN_NOTESTFILECREATE |
Do not create the file before the dialog A file cannot be reopened once it is closed. |
|
13 |
OFN_NOVALIDATE |
Invalid characters are allowed in file |
|
14 |
OFN_OVERWRITEPROMPT |
Used in Save As dialog boxes. Generates |
|
15 |
OFN_PATHMUSTEXIST |
Only valid paths and file names can be |
|
16 |
OFN_READONLY |
Select the Read Only check box when the |
Opening a file
Use the FileOpen function to open a selected
file.
Examples
The following example displays a Select File dialog
box that allows multiple selection. The file types are TXT, DOC,
and all files, and the initial directory is C:Program
FilesSybase. The option flag 18 specifies that
the Explorer–style dialog box is used (2^1 = 2),
and the Read Only check box is hidden (2^4 = 16). The selected
filenames are displayed in a MultiLineEdit control.
If the user selects a single file, the docpath variable
contains both the path and the file name. The example contains an
IF clause to allow for this.
|
1 |
string docpath, docname[]<br>integer i, li_cnt, li_rtn, li_filenum<br> <br> |
|
1 |
li_rtn = <span>GetFileOpenName</span>("Select File", &<br>   docpath, docname[], "DOC", &<br>   + "Text Files (*.TXT),*.TXT," &<br>   + "Doc Files (*.DOC),*.DOC," &<br>   + "All Files (*.*), *.*", &<br>   "C:Program FilesSybase", 18)<br> <br>mle_selected.text = ""<br>IF li_rtn < 1 THEN return<br>li_cnt = Upperbound(docname)<br> <br>// if only one file is picked, docpath contains the <br>// path and file name<br>if li_cnt = 1 then<br>   mle_selected.text = string(docpath)<br>else<br> <br>// if multiple files are picked, docpath contains the <br>// path only - concatenate docpath and docname<br>   for i=1 to li_cnt<br>      mle_selected.text += string(docpath) &<br>         + "" +(string(docname[i]))+"~r~n"<br>   next<br>end if |
In the following example, the dialog box has the
title Open and displays text files, batch files, and INI files in
the Files of Type drop-down list. The initial directory is d: emp.
The option flag 512 specifies that the old-style dialog box is used
and the Network button is hidden (2^9 = 512).
|
1 |
// instance variables<br>// string is_filename, is_fullname<br>int   li_fileid<br> <br>if <span>GetFileOpenName</span> ("Open", is_fullname, is_filename, &<br>   "txt", "Text Files (*.txt),*.txt,INI Files " &<br>   + "(*.ini), *.ini,Batch Files (*.bat),*.bat", &<br>   "d: emp", 512) < 1 then return<br> <br>li_fileid = FileOpen (is_fullname, StreamMode!)<br>FileRead (li_fileid, mle_notepad.text)<br>FileClose (li_fileid) |