FileUtils component methods

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: The following methods are available in version 8.0.1078 or later. If the FileUtils component does not appear in your Robotic Automation 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.

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.

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)

 8.0 SP1 2019 or later.

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)

8.0 SP1 2019 or later.

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

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

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

The source path of the directory that you want to move.

String destinationPath

The destination path to which you want to move the directory.

Boolean - Returns True if the method completed without exceptions.

MoveFile (2 params)

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

The source path of the file that you want to move.

String destinationPath

The destination path to which you want to move the file.

Boolean - Returns True if the method completed without exceptions.

 


Privacy | Trademarks | Terms of Use | Feedback

Updated: 18 June 2020

Copyright© 2016 - 2019  Pegasystems Inc.  Cambridge, MA All rights reserved.

 

OpenSpan data classification label