File Utility
Utility functions for the file system.
Quick Facts
| Property | Value |
|---|---|
| Class | FileUtility |
| Module | cenpylib.FileUtility |
| Package | cenpylib |
| Release | R2025.2.4 |
| Methods | 13 |
Quick Start
# Boilerplate Example
fileUtility = ... # obtained from the runtime context
result = fileUtility.GetWindowsUserName()Method Index
| Method | Returns | Summary |
|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
filePath | — | — |
ReadCSVColumnIntoList
def ReadCSVColumnIntoList(filePath, columnName)Read the CSV file and return the specified column as a list.
Parameters:
| Name | Type | Description |
|---|---|---|
filePath | — | — |
columnName | — | — |
GetFilesAndDirectoriesRecursively
def GetFilesAndDirectoriesRecursively(directoryPath)Recursively gets all files and all directories inside the given directory.
Parameters:
| Name | Type | Description |
|---|---|---|
directoryPath | — | — |
Mutation Methods
RemoveDirectory
def RemoveDirectory(directoryPath, ignoreErrors=True)Delete an entire directory tree, path must point to a directory.
Parameters:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
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:
| Name | Type | Description |
|---|---|---|
filePath | — | — |
block | — | — |
Version Notes
This class is documented as of release R2025.2.4.