-
Notifications
You must be signed in to change notification settings - Fork 0
Class File
Kristian Virtanen edited this page Oct 28, 2024
·
5 revisions
The File
class provides methods for performing common file and directory operations, such as reading, writing, copying, and deleting files, as well as managing directories. It also includes error handling via the LastError
property, which stores the most recent error message if an operation fails.
-
Description: Stores the last error message, if any operation fails, including a timestamp in
yyyy-MM-dd HH:mm:ss
format. -
Example:
"2024-10-16 14:30:00: No such file: C:\\example.txt"
- Difference from orig. SB: Not available on orig. SB.
- Description: Appends contents to the end of a file.
-
Parameters:
-
filePath
: The path of the file to append to. -
contents
: The content to append.
-
-
Returns:
true
if successful,false
if an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"
or"FAILED"
while SBOE returnstrue
orfalse
.
- Description: Copies a file from the source path to the destination path, overwriting the destination file if it exists.
-
Parameters:
-
sourceFilePath
: The path of the file to copy. -
destinationFilePath
: The path where the file should be copied to.
-
-
Returns:
true
if successful,false
if an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"
or"FAILED"
while SBOE returnstrue
orfalse
.
- Description: Creates a new directory at the specified path.
-
Parameters:
-
directoryPath
: The path of the directory to create.
-
-
Returns:
true
if successful,false
if an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"
or"FAILED"
while SBOE returnstrue
orfalse
.
- Description: Deletes the specified directory and all its contents.
-
Parameters:
-
directoryPath
: The path of the directory to delete.
-
-
Returns:
true
if successful,false
if an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"
or"FAILED"
while SBOE returnstrue
orfalse
.
- Description: Deletes the specified file.
-
Parameters:
-
filePath
: The path of the file to delete.
-
-
Returns:
true
if successful,false
if an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"
or"FAILED"
while SBOE returnstrue
orfalse
.
- Description: Retrieves all directory paths in the specified directory.
-
Parameters:
-
directoryPath
: The path of the directory to search for directories.
-
-
Returns: A string containing all directory paths in the directory, separated by newlines, or
null
if an error occurs. -
Difference from orig. SB: Original returns array of directories or
"FAILED"
while SBOE returns string of directories seperated by new line ornull
.
- Description: Retrieves all file paths in the specified directory.
-
Parameters:
-
directoryPath
: The path of the directory to search for files.
-
-
Returns: A string containing all file paths in the directory, separated by newlines, or
null
if an error occurs. -
Difference from orig. SB: Original returns array of files or
"FAILED"
while SBOE returns string of files seperated by new line ornull
.
- Description: Inserts a specific line in the file without overwriting existing lines.
-
Parameters:
-
filePath
: The path of the file to modify. -
lineNumber
: The line number to insert at (1-based). -
contents
: The content to insert at the specified line.
-
-
Returns:
true
if successful,false
if an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"
or"FAILED"
while SBOE returnstrue
orfalse
.
- Description: Reads the entire contents of a file.
-
Parameters:
-
filePath
: The path of the file to read.
-
-
Returns: The contents of the file as a string, or
null
if an error occurs. -
Difference from orig. SB: Original returns file contents as string or empty string. Instead of empty string, SBOE returns
null
if no contents available.
- Description: Reads a specific line from a file.
-
Parameters:
-
filePath
: The path of the file to read. -
lineNumber
: The line number to read (1-based).
-
-
Returns: The specified line as a string, or
null
if an error occurs. -
Difference from orig. SB: Original returns line as string or empty string. Instead of empty string, SBOE returns
null
if no content available.
- Description: Writes the specified contents to a file, overwriting the file if it exists.
-
Parameters:
-
filePath
: The path of the file to write to. -
contents
: The content to write to the file.
-
-
Returns:
true
if the operation was successful,false
if an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"
or"FAILED"
while SBOE returnstrue
orfalse
.
- Description: Writes a specific line in the file, overwriting the existing content at that line number.
-
Parameters:
-
filePath
: The path of the file to write to. -
lineNumber
: The line number to overwrite (1-based). -
contents
: The content to write to the line.
-
-
Returns:
true
if successful,false
if an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"
or"FAILED"
while SBOE returnstrue
orfalse
.