Open/Create/Replace File

Opens an existing file, creates a new file, or replaces an existing file, programmatically or interactively using a file dialog box. You can optionally specify a dialog prompt, default file name, start path, or filter pattern. Use this VI with the intermediate Write File or Read File functions.

pattern restricts the files displayed in the dialog box to those whose name matches pattern. pattern does not restrict the directories displayed. The pattern matching in this function is similar to the matching used in matching wildcards in Windows and UNIX filenames and is not like the regular expression matching performed by the Match Pattern function. If you specify characters other than the question mark character (?) or the asterisk character (*), the function displays only files or directories that contain those characters. You can use the question mark character (?) to match any single character. You can use the asterisk character (*) to match any sequence of one or more characters.

For example, a pattern of *.vi;test*.llb returns matches for any file with a .vi extension and any file whose filename begins with test and has an .llb extension.

To match multiple patterns, use a semicolon ( ; ) to separate the patterns. White space, such as blanks, tabs, and carriage returns, are taken literally. Avoid using white spaces unless they are part of the extension pattern. For example, if you use *.html;*.doc, File Dialog displays all files that end with .html and .doc. If you use *.html; *.doc, File Dialog displays only files that end with .html.

To use more than one pattern, wire a string constant or control into file pattern.

prompt is the message that appears above the list of files and directories, or folder, in the file dialog box.
file path is the path name of the file. If file path is empty (default) or is Not A Path, the VI displays a dialog box from which you can select a file. Error 43 occurs if you cancel the dialog box.
start path is the path name to the initially displayed directory, or folder, in a file dialog box. The default is Not A Path, which will use the path to the last directory,or folder, used in a file dialog box.
function is the operation to perform.

0Opens an existing file (default). Error 7 occurs if the file cannot be found.
1Opens an existing file or creates a new file if one does not exist.
2Creates a new file or replaces a file if it exists and you give permission. This VI replaces a file by opening the file and setting its end of file to 0. Error 43 occurs if you do not select the replacement in an advisory dialog box.
3Creates a new file. Error 8 occurs if the file already exists.
4Opens an existing file for read only. Error 7 occurs if the file cannot be found.
error in describes error conditions that occur before this VI or function runs. The default is no error. If an error occurred before this VI or function runs, the VI or function passes the error in value to error out. This VI or function runs normally only if no error occurs before this VI or function runs. If an error occurs while this VI or function runs, it runs normally and sets its own error status in error out. Use the Simple Error Handler or General Error Handler VIs to display the description of the error code. Use error in and error out to check errors and to specify execution order by wiring error out from one node to error in of the next node.
status is TRUE (X) if an error occurred before this VI or function ran or FALSE (checkmark) to indicate a warning or that no error occurred before this VI or function ran. The default is FALSE.
code is the error or warning code. The default is 0. If status is TRUE, code is a non-zero error code. If status is FALSE, code is 0 or a warning code.
source describes the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning. The default is an empty string.
default name is the name you want to appear as the initial file or directory name in the dialog box. The default is an empty string.
If advisory dialog? is TRUE (default), the VI displays a dialog box when function is 0 and the file does not exist, or when function is 2 or 3 and the file exists.
refnum is the reference number of the open file. The value is Not A Refnum if the file cannot be opened.
new file path is the path of the file opened or created. You can use this output to determine the path of a file that you open or create using a file dialog box. new file path returns Not A Path if you select Cancel from the dialog box.
file size is the size of the file in bytes. It is also the location of the end of file.
error out contains error information. If error in indicates that an error occurred before this VI or function ran, error out contains the same error information. Otherwise, it describes the error status that this VI or function produces. Right-click the error out indicator on the front panel and select Explain Error from the shortcut menu for more information about the error.
status is TRUE (X) if an error occurred or FALSE (checkmark) to indicate a warning or that no error occurred.
code is the error or warning code. If status is TRUE, code is a non-zero error code. If status is FALSE, code is 0 or a warning code.
source describes the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning.