Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

File methods

Updated on October 19, 2022

Use File methods to manipulate Windows files, folders, and paths in your automations.

Directory methods

MethodDescription
CopyDirectoryCopies the contents of a directory into another directory. You can optionally overwrite the files in the directory.
CreateDirectory

Creates all of the directories and subdirectories in the specified path. The path parameter specifies a directory path, not a file path.

DeleteDirectoryDeletes a directory at the path you specify, including all of its subdirectories and any files in those directories.
DirectoryExistsDetermines whether the specified directory exists.
GetDirectoriesInDirectoryReturns the paths of the subdirectories in the directory that you specify.
MoveDirectoryMoves 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.

RenameDirectoryRenames the directory that you specify.

File contents methods

MethodDescription
AppendAllLinesAppends lines to a file, and then closes the file.
AppendAllTextAppends the specified string to the file. Creates the file if it does not exist.
AppendTextCreates a StreamWriter that appends UTF-8 encoded text to a file or creates a new file with that text, if the specified file does not exist.
DecryptDecrypts a file that was encrypted by the current account using the Encrypt(String) method.
EncryptEncrypts a file so that only the account used to encrypt the file can decrypt it.
ReadAllBytesOpens a binary file, reads the contents of the file into a byte array, and then closes the file.
ReadAllLinesOpens a text file, reads all lines of the file into a string array, and then closes the file.
ReadAllTextOpens a text file, reads all the text in the file into a string, and then closes the file.
ReadLinesReads the lines of a file.
WriteAllBytesCreates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.
WriteAllLinesCreates a new file, writes one or more strings to the file, and then closes the file.
WriteAllTextCreates a new file, write the contents to the file, and then closes the file. If the target file already exists, the system overwrites it.

File management methods

MethodDescription
CopyFileCopies an existing file to a new file.
CreateFileCreates a file, writes the specified byte array to the file, and then closes the file. If the target file already exists, the system overwrites it.
DeleteFileDeletes the specified file.
FileExistsDetermines whether the specified file exists.
GetAttributesGets the FileAttributes of the specified file.
GetFileInfoReturns the creation date and last updated date for the specified file.
GetFilesReturns the names and paths of the files that meet specified criteria.
GetFilesInDirectoryReturns the names and paths of the files that meet specified criteria.
GetFilesUnderDirectoryDetermines if the specified file is in the specified directory.
MoveFileMoves a specified file to a new location, and provides the option to specify a new file name.
ReplaceFileReplaces the contents of a specified file with the contents of another file. Creates a backup of the original file and then deletes it.
SetAttributesSets the specified FileAttributes of the file on the specified path.
TouchFileUpdates the LastWriteTime and LastAccessTime for the specified file.

Find methods

MethodDescription
FindInFilesReturns a read-only collection of strings that represent the names of the files that contain the specified text.

Path methods

MethodDescription
CombinePathsCombines strings into a path.
GetDirectoryNameReturns the directory information for the specified path.
GetFileExtensionReturns the extension, including the period, of the specified path string.
GetFileNameReturns the file name and extension of the specified path string.
GetFileNameWithoutExtensionReturns the file name of the specified path string without the extension.
GetFullPathReturns the absolute path for the specified path string.
GetParentDirectoryReturns the directory information for the specified path.

Zip methods

MethodDescription
CreateZipFromDirectoryCreates a ZIP archive that contains the files and directories from the specified directory.
ExtractZipToDirectoryExtracts all the files in the specified ZIP archive to a directory on the file system.
OpenOpens a ZIP archive at the specified path and in the specified mode.
OpenReadOpens a ZIP archive for reading at the specified path.

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us