-
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:ssformat. -
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:
trueif successful,falseif an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"or"FAILED"while SBOE returnstrueorfalse.
- 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:
trueif successful,falseif an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"or"FAILED"while SBOE returnstrueorfalse.
- Description: Creates a new directory at the specified path.
-
Parameters:
-
directoryPath: The path of the directory to create.
-
-
Returns:
trueif successful,falseif an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"or"FAILED"while SBOE returnstrueorfalse.
- Description: Deletes the specified directory and all its contents.
-
Parameters:
-
directoryPath: The path of the directory to delete.
-
-
Returns:
trueif successful,falseif an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"or"FAILED"while SBOE returnstrueorfalse.
- Description: Deletes the specified file.
-
Parameters:
-
filePath: The path of the file to delete.
-
-
Returns:
trueif successful,falseif an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"or"FAILED"while SBOE returnstrueorfalse.
- 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
nullif 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
nullif 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:
trueif successful,falseif an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"or"FAILED"while SBOE returnstrueorfalse.
- 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
nullif an error occurs. -
Difference from orig. SB: Original returns file contents as string or empty string. Instead of empty string, SBOE returns
nullif 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
nullif an error occurs. -
Difference from orig. SB: Original returns line as string or empty string. Instead of empty string, SBOE returns
nullif 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:
trueif the operation was successful,falseif an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"or"FAILED"while SBOE returnstrueorfalse.
- 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:
trueif successful,falseif an error occurs. -
Difference from orig. SB: Original returns
"SUCCESS"or"FAILED"while SBOE returnstrueorfalse.