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
GetWindowsUserNameGet a name of the windows user.
GetCurrentDateAndTimeGet a date and time in the specified format.
GetFilenameWithoutExtension”Get the name of the file without extension from the given file path.
CopyDirectoryRecursivelyRecursively copy an entire directory tree to the given location.
CopyFileToDirectoryCopy a source file to the destination directory.
CopyMultipleFilesToDirectoryCopy a multiple source files to the destination directory.
CutAndPasteRecursively move a file or an entire directory tree to the given location.
RemoveDirectoryDelete an entire directory tree, path must point to a directory.
AppendTextToFileOpen a text file, append the given text and close it.
AppendTextArrayToFileOpen a text file, append the given text array and close it.
ReadCSVColumnIntoListRead the CSV file and return the specified column as a list.
GetFilesAndDirectoriesRecursivelyRecursively gets all files and all directories inside the given directory.
RunWinMergeCall 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 R2025.2.4.

Was this page helpful?