File Methods
File methods are used to read and write data to a file or portions of a file. Note that higher-level techniques for reading and writing to files are available from within the Application Builder user interface. For more information, see the book Introduction to Application Builder and “GUI Command Methods” on page 127.
Returns the contents in the given file name as a string. The string name is the absolute path to a file or a path given by the file scheme syntax.
Returns a CsReader that can be used to read line-by-line or character-by-character from the given file name.
Returns a CsBinaryReader that can be used to read from the given file byte-by-byte.
Writes the given string contents to the given file name.
Writes the given string contents to the given file name. If append is true, then the contents are appended instead of overwritten.
Writes the array data to the given file. The spreadsheet format is used, which means it can be read by readMatrixFromFile.
Writes the array data to the given file. The spreadsheet format is used, which means it can be read by readMatrixFromFile. If append is true, then the contents are appended instead of overwritten.
Writes the array data to the given file. The spreadsheet format is used, which means it can be read by readStringMatrixFromFile.
Writes the array data to the given file. The spreadsheet format is used, which means it can be read by readStringMatrixFromFile. If append is true, then the contents are appended instead of overwritten.
Returns a CsWriter that can write to the given file.
Returns a CsWriter that can write to the given file. If append is true, then the contents are appended instead of overwritten.
Returns a CsBinaryWriter that can be used to write to the given file byte-by-byte.
Returns a CsBinaryWriter that can be used to write to the given file byte by byte. If append is true, then the contents are appended instead of overwritten.
Writes the given string array data to a CSV file. The RFC 4180 format is used for the CSV.
Writes the given string array data to a CSV file. The RFC 4180 format is used for the CSV. If append is true, then the contents are appended instead of overwritten.
Writes the given double array data to a CSV file. The RFC 4180 format is used for the CSV.
Writes the given double array data to a CSV file. The RFC 4180 format is used for the CSV. If append is true, then the contents are appended instead of overwritten.
If the name is not a file scheme path name or an absolute path, then the method first finds out whether a file with file scheme path embedded:/// + argument exists. If such a file does not exist, then it tests whether there is a file with a matching name in the current working directory.
Displays a file browser dialog box and uploads the selected file to the file declaration with the given name. After this, the uploaded file can be accessed with upload:///<name>. The optional fileTypes argument can be used to filter which file types are available for selection in the file browser. The easiest way to get a list of valid file types is to use code completion in the Method Editor.
Writes the given string array data starting from the first cell in the first sheet of an Excel file. This method requires LiveLink™ for Excel®.
Writes the given string array data starting from the specified cell in the specified sheet of an Excel file. This method requires LiveLink™ for Excel®.
This method can be used to pass the path to, for example, a file using the temp:/// scheme to external code or an application.
In addition, this method is used to retrieve the file name of an uploaded file when using the file scheme upload:///inputFile, for example by using a File declaration together with a File Import form object.
Creates a file directory name, see examples below in the Example Code section.
Example Code
This line of code copies the uploaded file file1 to the temp folder with new file name file2.mphbin and then prompts the user to save the file to any location.
copyFile("upload:///file1", "temp:///file2.mphbin");
fileSaveAs("temp:///file2.mphbin");
This line of code deletes the file file2.mphbin from the temp folder.
deleteFile("temp:///file2.mphbin");
This line of code creates a directory in the user folder, as specified in Preferences.
createDirectory("user:///a/b");
This line of code creates a directory in the Temp folder under C:.
createDirectory("C:\\Temp\\a\\b");
Note that the method fileSaveAs returns a boolean that indicates if saving the file was successful or not. Saving a file will fail if, for example, the user does not have access to the target folder.