Skip to Content

File Utility

Utility functions for the file system.

Quick Facts

PropertyValue
ClassFileUtility
Modulecenpylib.FileUtility
Packagecenpylib
ReleaseR2025.2.4
Methods13

Quick Start

# Boilerplate Example fileUtility = ... # obtained from the runtime context result = fileUtility.GetWindowsUserName()

Method Index

MethodReturnsSummary
GetWindowsUserNameโ€”Get a name of the windows user.
GetCurrentDateAndTimeโ€”Get a date and time in the specified format.
GetFilenameWithoutExtensionโ€”โ€Get the name of the file without extension from the given file path.
CopyDirectoryRecursivelyโ€”Recursively copy an entire directory tree to the given location.
CopyFileToDirectoryโ€”Copy a source file to the destination directory.
CopyMultipleFilesToDirectoryโ€”Copy a multiple source files to the destination directory.
CutAndPasteโ€”Recursively move a file or an entire directory tree to the given location.
RemoveDirectoryโ€”Delete an entire directory tree, path must point to a directory.
AppendTextToFileโ€”Open a text file, append the given text and close it.
AppendTextArrayToFileโ€”Open a text file, append the given text array and close it.
ReadCSVColumnIntoListโ€”Read the CSV file and return the specified column as a list.
GetFilesAndDirectoriesRecursivelyโ€”Recursively gets all files and all directories inside the given directory.
RunWinMergeโ€”Call the WinMerge to compare original and modified files.

Query Methods

GetWindowsUserName

def GetWindowsUserName()

Get a name of the windows user.

GetCurrentDateAndTime

def GetCurrentDateAndTime(format='%d.%m.%Y %H:%M:%S')

Get a date and time in the specified format.

Parameters:

NameTypeDescription
formatโ€”โ€” (default: '%d.%m.%Y %H:%M:%S')

GetFilenameWithoutExtension

def GetFilenameWithoutExtension(filePath)

โ€œGet the name of the file without extension from the given file path.

Parameters:

NameTypeDescription
filePathโ€”โ€”

ReadCSVColumnIntoList

def ReadCSVColumnIntoList(filePath, columnName)

Read the CSV file and return the specified column as a list.

Parameters:

NameTypeDescription
filePathโ€”โ€”
columnNameโ€”โ€”

GetFilesAndDirectoriesRecursively

def GetFilesAndDirectoriesRecursively(directoryPath)

Recursively gets all files and all directories inside the given directory.

Parameters:

NameTypeDescription
directoryPathโ€”โ€”

Mutation Methods

RemoveDirectory

def RemoveDirectory(directoryPath, ignoreErrors=True)

Delete an entire directory tree, path must point to a directory.

Parameters:

NameTypeDescription
directoryPathโ€”โ€”
ignoreErrorsโ€”โ€” (default: True)

Execution & Actions

RunWinMerge

def RunWinMerge(winMergePath, leftFilePath, rightFilePath, reportFilePath=None, readonly=True, inBackground=False, useDefaultSettings=False)

Call the WinMerge to compare original and modified files.

Parameters:

NameTypeDescription
winMergePathโ€”โ€”
leftFilePathโ€”โ€”
rightFilePathโ€”โ€”
reportFilePathโ€”โ€” (default: None)
readonlyโ€”โ€” (default: True)
inBackgroundโ€”โ€” (default: False)
useDefaultSettingsโ€”โ€” (default: False)

Conversion & Serialization

CopyDirectoryRecursively

def CopyDirectoryRecursively(sourceDirectory, destinationDirectory)

Recursively copy an entire directory tree to the given location. Create the destination directory if it does not exist. Replace the destination directory if it exists.

Parameters:

NameTypeDescription
sourceDirectoryโ€”โ€”
destinationDirectoryโ€”โ€”

CopyFileToDirectory

def CopyFileToDirectory(sourceFile, destinationDirectory)

Copy a source file to the destination directory. Create the destination directory if it does not exist. Replace the destination file if it exists.

Parameters:

NameTypeDescription
sourceFileโ€”โ€”
destinationDirectoryโ€”โ€”

CopyMultipleFilesToDirectory

def CopyMultipleFilesToDirectory(sourceFiles, destinationDirectory)

Copy a multiple source files to the destination directory. Create the destination directory if it does not exist. Replace the destination files if they exist.

Parameters:

NameTypeDescription
sourceFilesโ€”โ€”
destinationDirectoryโ€”โ€”

Utilities

CutAndPaste

def CutAndPaste(source, destinationDirectory)

Recursively move a file or an entire directory tree to the given location. Create the destination directory if it does not exist. Replace the destination directory if it exists.

Parameters:

NameTypeDescription
sourceโ€”โ€”
destinationDirectoryโ€”โ€”

AppendTextToFile

def AppendTextToFile(filePath, text)

Open a text file, append the given text and close it. Create a new file if it does not exist.

Parameters:

NameTypeDescription
filePathโ€”โ€”
textโ€”โ€”

AppendTextArrayToFile

def AppendTextArrayToFile(filePath, block)

Open a text file, append the given text array and close it. Create a new file if it does not exist.

Parameters:

NameTypeDescription
filePathโ€”โ€”
blockโ€”โ€”

Version Notes

This class is documented as of release R2026.1.1.

Was this page helpful?