File
(Available from version 7.0 onwards.)
Functions
Checks if the specified directory/folder exists.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Path |
Text |
The directory/folder name. |
Returns
Returns True (if the directory/folder exists) or False (if it dies not).
Example
This example checks if the C:\TEST directory exists and returns the result into the TestBoolean variable.
Checks if the specified file exists.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Path |
Text |
The full path and file name. |
Returns
Returns True (if the file exists) or False (if the file does not exist in the specified location).
Example
This example checks if C:\TEST\abc.txt exists and returns the result into the TestBoolean variable.
Copies the source directory (and its contents) to the destination directory (if the directory does not exist, it is created). If the overwrite option is set to True and the destination directory already exists, any files in the destination directory with the same names as those in the source directory are overwritten.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Source path |
Text |
The source directory. |
Destination path |
Text |
The destination directory |
Overwrite |
Boolean |
Whether or not to overwrite the destination directory if it exists. |
Returns
Returns True (successful) or False (failed).
Example
This example copies C:\Test to C:\Test99 and returns the result into the TestBoolean variable. If C:\Test99 already exists, then no files are copied (as the overwrite is set to False).
Copies the file from the source path to the destination path, and renames the file (if a new file name is specified).
If a file with the specified name already exists at the specified location, the existing file will not be overwritten. If the solution is required to overwrite an existing file, first delete the existing file using the Delete File function.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
File name |
Text |
The file to copy. |
Source path |
Text |
The source directory. |
Destination path |
Text |
The destination directory. This must exist - if it does not exist, the file will not be copied. |
New file name |
text |
The new file name. |
Returns
Nothing.
Example
This example copies Test100.docs from C:\Test to Test101.docs in C:\Test99.
Creates the specified directory.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Path |
Text |
The directory to create. |
Returns
Returns True (successful) or False (failed).
Example
This example creates C:\Test and returns the result into the TestBoolean variable. If the directory already exists, then the function returns False.
Deletes the specified directory and all its child directories, if the recursively option is set to True. If the recursively option is set to False and there are child directories, then the directory is not deleted. If there are no child directories, then the directory is deleted, irrespective of the recursively option .
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Path |
Text |
The directory to delete. |
Recursively |
Boolean |
Whether or not to delete the directory if there are child directories. |
Returns
Returns True (successful) or False (failed).
Example
This example deletes C:\Test and all its child directories, and returns the result into the TestBoolean variable.
Deletes the specified file.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Path |
Text |
The full path and file name. |
Returns
Nothing.
Example
This example deletes C:\Test\Test101.docx.
Retrieves a text list of all encodings available in the current environment.
Parameters
No parameters
Returns
Returns a text list where each element stores information about a single encoding, for example:
Code Page: 51932, Name: euc-jp, Full Name: Japanese (EUC)
Example
The workflow below retrieves the list of all available encodings and stores that in the text list Available_Encodings.
When run, the variable Available_Encodings is populated, as shown below.
Populates all properties of a specified variable of type File Information with details of the file already specified within that variable's File Information property.
For a demonstration of how to use this function, see the example below.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
file information |
File Information |
The name of the File Information variable to populate |
Returns
Nothing.
Example
A project includes a variable FileInfo which is of type File Information, as shown below with its properties.
The workflow described below is intended to populate the FileInfo variable with the properties of the file shown below.
The first step of this workflow populates the File Name property of the FileInfo variable with the full path c:/temp/test.xlsx.
The second step of the workflow uses the Get File Information function to populate the rest of the properties of FileInfo.
After the first step is executed, only the File Name property of the FileInfo variable is populated. (Some other properties are populated with default values.)
After the second step is executed, all properties are populated with information about the file that was specified in the File Name property.
Retrieves file information about all files in a specified folder. You can optionally specify to only retrieve information about files with a specified extension.
Parameter |
Input Type |
Description |
---|---|---|
extension |
Text |
The file extension to filter by, for example, pdf or png. Set to Empty Text if you don't want to set an extension filter. This parameter is case sensitive. |
folder path |
Text |
The full path to the folder that contains the files. System variables like %APPDATA% can be used in the path. |
Returns
Returns a list of type File Information where each element stores information about one file in the folder.
Example
This workflow retrieves file information on all files with an extension of txt from the folder c:\Mydocs and stores the information in the variable Info_on_Files which is a list variable of type File Information.
When run, two matching files were found. File information is provided for both.
To retrieve file information on all files in the folder, the extension must be set to Empty Text, as below.
Retrieves file information about all files in a specified folder and subfolders of that folder. You can optionally specify to only retrieve information about files with a specified extension.
Parameter |
Input Type |
Description |
---|---|---|
extension |
Text |
The file extension to filter by, for example, pdf or png. Set to Empty Text if you don't want to set an extension filter. This parameter is case sensitive. |
folder path |
Text |
The full path to the folder that contains the files. System variables like %APPDATA% can be used in the path. |
Returns
Returns a list of type File Information where each entry stores information about one file in the folder.
Example
This workflow retrieves file information on all files with an extension of txt from the folder c:\Mydocs and its subfolders, and stores the information in the variable Info_on_Files which is a list variable of type File Information.
When run, three matching files were found. File information is provided for all. You can see that the file found below is located in a subfolder of the folder specified in the workflow.
Moves the source directory to the destination directory. If the directory already exists in the destination path, and the allow overwrite option is set to True, the directory is overwritten.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Source path |
Text |
The source directory. |
Destination path |
Text |
The destination path. |
Allow overwrite |
Boolean |
Whether or not to overwrite the destination directory. |
Returns
Nothing.
Example
This example moves from C:\Test to D:\Test.
Moves the file from the source directory to the destination directory. If the file already exists in the destination directory, and the allow overwrite option is set to True, the file is overwritten.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
File name |
Text |
The file name. |
Source path |
Text |
The source directory. |
Destination path |
Text |
The destination directory. |
Allow overwrite |
Boolean |
Whether or not to overwrite the destination file. |
Returns
Nothing.
Example
This example moves abc.text from C:\Test to D:Test.
Reads the text in the specified file, located in the specified directory.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
file name |
Text |
The file name. |
directory |
Text |
The full path to the file. |
Returns
Returns the text from the file as text.
Example
This returns the text in the file C:\TEST\abc.txt , and returns the result into the TestTextvariable.
Retrieve the textual content of the specified file using the encoding specified by code page number.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
file name |
Text |
The file name. |
directory |
Text |
The full path to the file. |
code page | Number | The code page number for the encoding to be used. |
Returns
Returns the text from the file as text.
Example
The workflow below reads the text from the file created in the example for Write Text to File with Encoding. The file text is written to the text variable readText.
When run, the variable readText is populated with the contents of the file.
Renames the specified directory. If the new directory name already exists, and the allow overwrite option is set to True, the destination directory is overwritten.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Source path |
Text |
The existing directory name and full path. |
New directory name |
Text |
The new directory name without the path. |
Allow overwrite |
Boolean |
Whether or not to overwrite the destination directory. |
Returns
Returns True (successful) or False (failed).
Example
This example renames C:\Test to c:\Test99, and returns the result into the TestBooleanvariable.
Renames the file in the specified directory.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Source file name |
Text |
The file name. |
Path |
text |
The full path to the directory . |
newFileName |
text |
The new file name. |
Returns
Nothing.
Example
This example renames abc.txt in C:\Test to xyz.txt.
Displays the standard Windows Browse for File dialog. Optionally specify:
-
Dialog title
-
The file or folder to be selected by default
-
The file extension to filter by
-
Whether to show a Save or Open button.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
title |
Text |
The dialog title. |
full path |
Text |
The full path to the default file to select, or to the default folder to select from. System variables like %APPDATA% can be used in the path. |
extension | Text |
The file extension to filter by, for example, pdf or png. This parameter is case sensitive. |
Save mode | Boolean | Set to True to show a Save button, or False to show an Open button. |
All parameters can be set to Empty Text to use default settings.
Returns
Returns the full path to the selected file as text.
Example
This workflow opens the Browse for File dialog;
-
The dialog title is set to "Select a File".
-
The default file selected is file_001.txt in the folder c:/MyDocs.
-
The extension filter is set to txt. Only files with txt extensions are shown in the dialog.
-
Save mode is set to False, so the dialog is shown with an Open button.
The response from this function is stored in the text variable textVar.
When run, the Browse for File dialog is displayed as shown below. Note how it is customized according to the settings in the workflow.
If the user changes the file name to file_a.txt and then clicks Open, the dialog closes and the path to the selected file is stored in the variable textVar.
In the alternative workflow below, the Default File parameter is set to a path without a file name.
When run, the Browse for File dialog is displayed as shown below. Note that no file is selected in the File name field.
Displays the standard Windows Browse for Folder dialog. Optionally specify:
-
Dialog title
-
Description to display below the title
-
The folder to be selected by default
Parameters
Parameter |
Input Type |
Description |
---|---|---|
title |
Text |
The dialog title. |
description | Text | The description to show below the dialog title. |
full path |
Text |
The full path to the default folder to select, for example: C:\MyDocs. (In this case it is important to use backslashes \ and not forward slashes /.) System variables like %APPDATA% can be used in the path. |
All parameters can be set to Empty Text to use default settings.
Returns
Returns the full path to the selected folder as text.
Example
The workflow below opens the Browse for Folder dialog:
-
The dialog title is set to Choose a Folder.
-
The dialog description is set to Where do you want to save the files?.
-
The default folder selected is c:/MyDocs.
The response from this function is stored in the text variable textVar.
When run, the Browse for Folder dialog is displayed as shown below. Note how it is customized according to the settings in the workflow.
The folder the user selects is written to the text variable textVar.
Write text to the specified file located in the specified directory.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
Input text |
Text |
The text to write to the file. |
File |
Text |
The file name. If the file does not exist it is created. |
Path |
Text |
The full path and directory name. The directory must exist. |
Append to file |
Boolean |
If set to False, the text in the file is overwritten. If set to True, the text is appended to the file. |
Returns
Returns True (successful) or False (failed).
Example
This example appends Hello World to the text in the abc.txt file in C:\Test, and returns the result into the TestBooleanvariable.
Writes text to the specified file located in the specified directory, using the specified encoding.
Parameters
Parameter |
Input Type |
Description |
---|---|---|
text |
Text |
The text to write to the file. |
directory |
Text |
The full path to the directory. The directory must exist. |
file name |
Text |
The file name. If the file does not exist it is created. |
Append to file |
Boolean |
If set to False, the text in the file is overwritten. If set to True, the text is appended to the file. |
Returns
Returns True (successful) or False (failed).
Example
This workflow writes Japanese text to a text file at c:/temp/enc_test.txt using encoding code page 932. The response is written to the Boolean variable writeTest.
Code page 932 is available in the environment, as can be seen from the Debug panel below after running the example for Get Available Encodings.
When run, the file is created and its contents are correctly encoded.
The Boolean variable writeTest is set to True, indicating that the operation was successful.