To manipulate directories and files, use the following methods available in the FileUtils component. These methods expose their corresponding .NET methods. For more information, see the Microsoft .NET documentation.
Do not include invalid path characters or lengths in the path parameters and be sure to comply with all security and I/O protocols. Unauthorized access or I/O exceptions prevent the system from executing the method.
Note: If the FileUtils component does not appear in your Pega Robot Studio toolbox, you can add it. For more information, see Adding Toolbox Items.
Method |
Description |
Parameters |
Result type |
CombinePaths (2+ params) |
Combines two or more strings into a single path. If one of the paths you specify is a zero-length string, this method returns the other path. If the second path contains an absolute path, this method returns second path. Review the following examples: When you combine 'c:\temp' and 'subdir\file.txt', the result is: 'c:\temp\subdir\file.txt' When you combine 'c:\temp' and 'c:\temp.txt', the result is: 'c:\temp.txt' When you combine 'c:\temp.txt' and 'subdir\file.txt', the result is: 'c:\temp.txt\subdir\file.txt' |
String paths The paths you want to combine. |
String - Returns a new string which is the result of combining the input paths. |
CopyDirectory (3 params) (19.1.22 or later)
|
Copies the contents of a directory into another directory. |
String sourceDirectoryName Enter the path to the source directory. String destinationDirectoryName Enter the path to the destination directory String message Returns the exception message if the result is false. |
Boolean - Returns True if the method completed without exceptions. |
CopyDirectory (4 params) (19.1.22 or later) |
Copies the contents of a directory into another directory. You can optionally overwrite the files in the directory. |
String sourceDirectoryName Enter the path to the source directory. String destinationDirectoryName Enter the path to the destination directory Boolean overwrite Enter True to overwrite the contents of the destination directory. String message Returns the exception message if the result is false. |
Boolean - Returns True if the method completed without exceptions. |
CopyFile (2 params) |
Copies a file to a new location. You cannot use this method to overwrite a file.
|
String sourcePath The source path you want to copy. String destinationPath The destination of the copy. |
Boolean - Returns True if the method completed without exceptions. |
CopyFile (3 params) |
Copies a file to a new location. You cannot use this method to overwrite a file.
|
String sourcePath The source path you want to copy. String destinationPath The destination of the copy. Boolean overwriteDestination If the destination path already exists, this toggles whether to copy and overwrite the destination path or not. |
Boolean - Returns True if the method completed without exceptions. |
CreateDirectory |
Creates all of the directories and subdirectories in the specified path. The path parameter specifies a directory path, not a file path.
|
String path The path to create the directory. |
Boolean - Returns True if the method completed without exceptions. |
CreateFile (2 params) |
Creates or overwrites a file in the path you specify. By default, the method grants full read and write access to the new files to all users. |
String filePath The path to create the file. Boolean overwriteDestination If the destination path already exists, this toggles whether to copy and overwrite the destination path or not. |
Boolean - Returns True if the method completed without exceptions. |
DeleteDirectory |
Deletes a directory at the path you specify, including all of its subdirectories and any files in those directories. |
String path The path of the directory to delete. |
Boolean - Returns True if the method completed without exceptions. |
DeleteFile |
Deletes a file at the path that you specify.
|
String filePath The path to the file to delete. |
Boolean - Returns True if the method completed without exceptions. |
DirectoryExists |
Determines whether the specified directory exists.
|
String filePath The path of the directory to check. |
Boolean - Returns True if the specified path exists. If you do not have sufficient permissions to read the specified path, the method returns False. |
FileExists |
Determines whether the specified file exists.
|
String filePath The path of the file to check. |
Boolean - Returns True if the specified file path exists. If you do not have sufficient permissions to read the specified file, the method returns False. |
FindInFiles (4 params) (19.1.22 or later) |
Returns a read-only collection of strings that represent the full paths to the files that contain the specified text. |
String directory Enter the name and path of the source directory. String containsText Enter the text that you want the system to search for. bool ignoreCase Enter True for a case-insensitive search. SearchOption searchType Choose from these options: SearchTopLevelOnly or SeachAllSubDirectories. |
String - Returns a string array with the file paths. |
FindInFiles (5 params) (19.1.22 or later) |
Returns a read-only collection of strings that represent the full paths to the files that contain the specified text. |
String directory Enter the name and path of the source directory. String containsText Enter the text that you want the system to search for. bool ignoreCase Enter True for a case-insensitive search. SearchOption searchType Choose from these options: SearchTopLevelOnly or SeachAllSubDirectories. String fileWildCards Enter a string array of patterns for matching files, such as *.txt or *.pdf. Each pattern is contained in its own element of the string array. Any file that matches one of the patterns is evaluated in the Find operation. |
String - Returns a string array with the file paths. |
GetDirectoriesInDirectory |
Returns the paths of the subdirectories in the directory that you specify. |
String path The directory to search through. |
IList<String> - Returns a list of the directory paths in the specified directory. |
GetDirectoryName |
Gets the directory name of the specified path. Note: To get the name of the directory and not just the path, use the GetFileName method on the directory path. Review the following examples: Input 'c:\MyDir\MySubDir\file.ext' returns 'c:\MyDir\MySubDir' Input 'c:\MyDir\MySubDir' returns 'c:\MyDir' Input 'c:\MyDir\' returns 'c:\MyDir' Input 'c:\' returns ’’ |
String path The path of the directory to return. |
String - Returns the directory information of the given path. |
GetFileExtension |
Returns the extension of the specified path string. Review the following examples: Input 'c:\mydir.old\myfile.ext') returns '.ext' Input 'c:\mydir.old\' returns ’’ |
String filePath The path to the file to get the extension from. |
String - Returns the file extension of the file. |
GetFileName |
Returns the file name and extension of the specified path string. Note: This method does not verify that the path or file name exists. Review the following examples: Input 'c:\mydir\myfile.ext' returns 'myfile Input 'c:\mydir\' returns ’’ |
String path The path of the file to return. |
String - Returns the directory information of the given path. |
GetFileNameWithoutExtension |
Returns the file name of the specified path string without the extension. Note: This method does not verify that the path or file name exists. Review the following examples: Input 'C:\mydir\myfile.ext' returns 'myfile.ext' Input 'C:\mydir\' returns ‘’ |
String path The path of the file to return. |
String - Returns the directory information of the given path without the file extension. |
GetFilesInDirectory |
Returns the paths of files in the specified directory. |
String path The directory to search through. |
IList<String>. Returns a list of the file paths in the specified directory. |
GetFilesInDirectory (2 params) |
Returns the paths of files in the specified directory.
|
String path The directory to search through. String searchPattern The string to search for. |
IList<String>. Returns a list of the file paths that match the search criteria. |
GetFilesInDirectory (3 params) |
Returns the paths of files in the specified directory. |
String path The directory to search through. String searchPattern The string to search for. SearchOption searchOption The options are: TopDirectoryOnly and AllDirectories. The default is TopDirectoryOnly. |
IList<String>. Returns a list of the file paths that match the search criteria. |
GetFullPath |
Returns the absolute path for the specified path string. Note: This method does not verify that the file or directory specified by the path exists.
|
String path Enter the path of the item to return. |
String - Returns the absolute path of the given path. |
GetParentDirectory |
Retrieves the absolute parent directory of the path that you specify. |
String path Enter the path in the parent directory to return. |
String - Returns the path of the parent directory of the given path. |
MoveDirectory (2 params) |
Moves a file or a directory and its contents to a new location. If you try to move a directory to a directory that already exists, nothing is moved and the method returns False. |
String sourcePath Enter the source path of the directory that you want to move. String destinationPath Enter the destination path to which you want to move the directory. |
Boolean - Returns True if the method completed without exceptions. |
MoveFile (2 params) (19.1.22 or later) |
Moves the file that you specify to a new location. You can change the name of the file during the move. The source and destination paths cannot be the same. |
String sourcePath Enter the source path of the file that you want to move. String destinationPath Enter the destination path to which you want to move the file. |
Boolean - Returns True if the method completed without exceptions. |
MoveFile (3 params) (19.1.22 or later) |
Moves the file that you specify to a new location. You can change the name of the file during the move and you can overwrite the file during the move. The source and destination paths cannot be the same. |
String sourcePath Enter the source path of the file that you want to move. String destinationPath Enter the destination path to which you want to move the file. Boolean overwrite Enter True to overwrite the file in the destination directory. String message Returns the exception message if the result is false. |
Boolean - Returns True if the method completed without exceptions. |
RenameDirectory (3 params) (19.1.22 or later) |
Renames the directory that you specify. |
String directory Enter the full path to the directory that you want to rename. String newName Enter the new name for the directory. Omit the path. String message Returns the exception message if the result is false. |
Boolean - Returns True if the method completed without exceptions. |
Privacy | Trademarks | Terms of Use | Feedback
Updated: 01 July 2024
Copyright © 2016 - 2024 Pegasystems Inc. Cambridge, MA All rights reserved.