![]() |
BogaNet 1.4.0
|
Various helper functions for filesystem operations. More...
Static Public Member Functions | |
static bool | IsUnixPath (string? path) |
Checks if the given path is from a Unix-device. | |
static bool | IsWindowsPath (string? path) |
Checks if the given path is from a Windows-device. | |
static bool | IsUNCPath (string? path) |
Checks if the given path is UNC. | |
static bool | IsURL (string? path) |
Checks if the given path is an URL. | |
static string | ValidatePath (string path, bool addEndDelimiter=true, bool preserveFile=true, bool removeInvalidChars=true) |
Validates a given path and add missing slash. | |
static string | ValidateFile (string path, bool removeInvalidChars=true) |
Validates a given file. | |
static bool | HasPathInvalidChars (string? path, bool ignoreNullOrEmpty=true) |
Checks a given path for invalid characters. | |
static bool | HasFileInvalidChars (string? file, bool ignoreNullOrEmpty=true) |
Checks a given file for invalid characters. | |
static string[] | GetFilesForName (string path, bool isRecursive=false, params string[]? filenames) |
Find files inside a path. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static string[] | GetFiles (string path, bool isRecursive=false, params string[]? extensions) |
Find files inside a path. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static string[] | GetDirectories (string path, bool isRecursive=false) |
Find directories inside a path. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static string[] | GetDrives () |
Find all logical drives. | |
static DriveInfo[] | GetDriveInfo () |
Gathers all information for all logical drives. | |
static string | Combine (string path1, string path2) |
Combines two paths together. | |
static bool | Copy (string sourcePath, string destPath, bool move=false, bool moveSafe=true) |
Copy or move a file or directory. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static bool | CopyFile (string sourceFile, string destFile, bool move=false, bool moveSafe=true) |
Copy or move a file. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static bool | CopyDirectory (string sourceDir, string destDir, bool move=false, bool moveSafe=true) |
Copy or move a directory. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static bool | Move (string sourcePath, string destPath) |
Move a file or directory. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static bool | MoveFile (string sourceFile, string destFile) |
Move a file. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static bool | MoveDirectory (string sourceDir, string destDir) |
Move a directory. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static string | Rename (string path, string newName) |
Renames a file or directory. | |
static string | RenameFile (string path, string newName) |
Renames a file in a path. | |
static string | RenameDirectory (string path, string newName) |
Renames a directory in a path. | |
static bool | Delete (string path) |
Delete a file or directory. | |
static bool | DeleteFile (string file) |
Delete a file. | |
static bool | DeleteDirectory (string dir) |
Delete a directory. NOTE: for a non-blocking version, consider calling this method from a separate thread. | |
static bool | Exists (string path) |
Checks if a file or directory exists. | |
static bool | ExistsFile (string path) |
Checks if a file exists. | |
static bool | ExistsDirectory (string path) |
Checks if a directory exists. | |
static string | CreateFile (string path, string fileName) |
Creates a file in a given path. | |
static string | CreateDirectory (string path, string folderName) |
Creates a directory in a given path. | |
static bool | CreateFile (string path) |
Creates a file. | |
static bool | CreateDirectory (string path) |
Creates a directory. | |
static bool | IsDirectory (string? path, bool checkForExtensions=true) |
Checks if the path is a directory. | |
static bool | IsFile (string? path, bool checkForExtensions=true) |
Checks if the path is a file. | |
static bool | IsRoot (string? path) |
Checks if the path is the root. | |
static string | GetName (string path) |
Returns the name for the file or directory. | |
static string | GetFileName (string path, bool removeInvalidChars=true) |
Returns the file name for the path. | |
static string | GetDirectoryName (string path, bool fullPath=false) |
Returns the directory name for the path. | |
static long | GetSize (string path) |
Returns the size of a file or directory in bytes. | |
static long | GetFileSize (string path) |
Returns the size of a file in bytes. | |
static long | GetDirectorySize (string path) |
Returns the size of a directory in bytes. | |
static string | GetExtension (string path) |
Returns the extension of a file. | |
static DateTime | GetLastWriteTime (string path) |
Returns the last write (=modified) timestamp of a file or directory. | |
static DateTime | GetLastAccessTime (string path) |
Returns the last access (=read) timestamp of a file or directory. | |
static DateTime | GetCreationTime (string path) |
Returns the creation timestamp of a file or directory. | |
static DateTime | GetLastFileWriteTime (string file) |
Returns the last write (=modified) timestamp of a file. | |
static DateTime | GetLastFileAccessTime (string file) |
Returns the last access (=read) timestamp of a file. | |
static DateTime | GetFileCreationTime (string file) |
Returns the creation timestamp of a file. | |
static DateTime | GetLastDirectoryWriteTime (string path) |
Returns the last write (=modified) timestamp of directory. | |
static DateTime | GetLastDirectoryAccessTime (string path) |
Returns the last access (=read) timestamp of a directory. | |
static DateTime | GetDirectoryCreationTime (string path) |
Returns the creation timestamp of a directory. | |
static string | ReadAllText (string path, Encoding? encoding=null) |
Reads the text of a file. | |
static async Task< string > | ReadAllTextAsync (string path, Encoding? encoding=null) |
Reads the text of a file asynchronously. | |
static string[] | ReadAllLines (string path, Encoding? encoding=null) |
Reads all lines of text from a file. | |
static async Task< string[]> | ReadAllLinesAsync (string path, Encoding? encoding=null) |
Reads all lines of text from a file asynchronously. | |
static byte[] | ReadAllBytes (string path) |
Reads the bytes of a file. | |
static async Task< byte[]> | ReadAllBytesAsync (string path) |
Reads the bytes of a file asynchronously. | |
static bool | WriteAllText (string destFile, string text, Encoding? encoding=null) |
Writes text to a file. | |
static async Task< bool > | WriteAllTextAsync (string destFile, string text, Encoding? encoding=null) |
Writes text to a file asynchronously. | |
static bool | WriteAllLines (string destFile, string[] lines, Encoding? encoding=null) |
Writes all lines of text to a file. | |
static async Task< bool > | WriteAllLinesAsync (string destFile, string[] lines, Encoding? encoding=null) |
Writes all lines of text to a file asynchronously. | |
static bool | WriteAllBytes (string destFile, byte[] data) |
Writes bytes to a file. | |
static async Task< bool > | WriteAllBytesAsync (string destFile, byte[] data) |
Writes bytes to a file asynchronously. | |
static bool | Show (string? path) |
Shows the location of a file or directory in OS file explorer. NOTE: only works on standalone platforms. | |
static bool | OpenFile (string? file) |
Opens a file with the OS default application. NOTE: only works for standalone platforms. | |
Properties | |
static string | TempFile [get] |
Returns a temporary file. | |
static string | TempPath [get] |
Returns the temporary directory path. | |
static string | TempDirectory [get] |
Returns a temporary directory. | |
static string | CurrentDirectory [get] |
Returns the current directory. | |
Various helper functions for filesystem operations.
|
static |
Combines two paths together.
path1 | First path |
path2 | Second path |
ArgumentNullException |
|
static |
Copy or move a file or directory. NOTE: for a non-blocking version, consider calling this method from a separate thread.
sourcePath | Source file/directory path |
destPath | Destination file/directory path |
move | Move file/directory instead of copy (optional, default: false) |
moveSafe | Moves a file/directory in a safe, but slower way (optional, default: true) |
Exception |
|
static |
Copy or move a directory. NOTE: for a non-blocking version, consider calling this method from a separate thread.
sourceDir | Source directory path |
destDir | Destination directory path |
move | Move directory instead of copy (optional, default: false) |
moveSafe | Moves a directory in a safe, but slower way (optional, default: true) |
Exception |
|
static |
Copy or move a file. NOTE: for a non-blocking version, consider calling this method from a separate thread.
sourceFile | Source file path |
destFile | Destination file path |
move | Move file instead of copy (optional, default: false) |
moveSafe | Moves a file in a safe, but slower way (optional, default: true) |
Exception |
|
static |
Creates a directory.
path | Path to the directory to create |
Exception |
|
static |
Creates a directory in a given path.
path | Path for the directory |
folderName | New folder |
Exception |
|
static |
Creates a file.
path | Path to the file to create |
Exception |
|
static |
Creates a file in a given path.
path | Path for the file |
fileName | New file |
Exception |
|
static |
Delete a file or directory.
path | Delete file/directory |
Exception |
|
static |
Delete a directory. NOTE: for a non-blocking version, consider calling this method from a separate thread.
dir | Directory to delete |
Exception |
|
static |
Delete a file.
file | File to delete |
Exception |
|
static |
Checks if a file or directory exists.
path | Path to the file or directory |
ArgumentNullException |
|
static |
Checks if a directory exists.
path | Path to the directory |
|
static |
Checks if a file exists.
path | Path to the file |
|
static |
Returns the creation timestamp of a file or directory.
path | Path to the file/directory |
Exception |
|
static |
Find directories inside a path. NOTE: for a non-blocking version, consider calling this method from a separate thread.
path | Path to find the directories |
isRecursive | Recursive search (optional, default: false) |
Exception |
|
static |
Returns the creation timestamp of a directory.
path | Path to the directory |
Exception |
|
static |
Returns the directory name for the path.
path | Path to the directory |
fullPath | Return the full path to the directory (optional, default: false) |
Exception |
|
static |
Returns the size of a directory in bytes.
path | Path of the directory |
Exception |
|
static |
Gathers all information for all logical drives.
|
static |
Find all logical drives.
Exception |
|
static |
Returns the extension of a file.
path | Path to the file |
Exception |
|
static |
Returns the creation timestamp of a file.
file | Path to the file |
Exception |
|
static |
Returns the file name for the path.
path | Path to the file |
removeInvalidChars | Removes invalid characters in the file name (optional, default: true) |
|
static |
Find files inside a path. NOTE: for a non-blocking version, consider calling this method from a separate thread.
path | Path to find the files |
isRecursive | Recursive search (optional, default: false) |
extensions | Extensions for the file search, e.g. "png" (optional) |
Exception |
|
static |
Find files inside a path. NOTE: for a non-blocking version, consider calling this method from a separate thread.
path | Path to find the files |
isRecursive | Recursive search (optional, default: false) |
filenames | Array of file names for the file search, e.g. "Image.png" (optional) |
Exception |
|
static |
Returns the size of a file in bytes.
path | Path of the file |
Exception |
|
static |
Returns the last access (=read) timestamp of a file or directory.
path | Path to the file/directory |
Exception |
|
static |
Returns the last access (=read) timestamp of a directory.
path | Path to the directory |
Exception |
|
static |
Returns the last write (=modified) timestamp of directory.
path | Path to the directory |
Exception |
|
static |
Returns the last access (=read) timestamp of a file.
file | Path to the file |
Exception |
|
static |
Returns the last write (=modified) timestamp of a file.
file | Path to the file |
Exception |
|
static |
Returns the last write (=modified) timestamp of a file or directory.
path | Path to the file/directory |
Exception |
|
static |
Returns the name for the file or directory.
path | Path to the file/directory |
|
static |
Returns the size of a file or directory in bytes.
path | Path of the file/directory |
Exception |
|
static |
Checks a given file for invalid characters.
file | File to check for invalid characters |
ignoreNullOrEmpty | If set to true, return false for null or empty paths (optional, default: true) |
|
static |
Checks a given path for invalid characters.
path | Path to check for invalid characters |
ignoreNullOrEmpty | If set to true, return false for null or empty paths (optional, default: true) |
|
static |
Checks if the path is a directory.
path | Path to the directory |
checkForExtensions | Check for extensions (optional, default: true) |
|
static |
Checks if the path is a file.
path | Path to the file |
checkForExtensions | Check for extensions (optional, default: true) |
|
static |
Checks if the path is the root.
path | Possible root |
|
static |
Checks if the given path is UNC.
path | Path to check |
|
static |
Checks if the given path is from a Unix-device.
path | Path to check |
|
static |
Checks if the given path is an URL.
path | Path to check |
|
static |
Checks if the given path is from a Windows-device.
path | Path to check |
|
static |
Move a file or directory. NOTE: for a non-blocking version, consider calling this method from a separate thread.
sourcePath | Source file/directory path |
destPath | Destination file/directory path |
Exception |
|
static |
Move a directory. NOTE: for a non-blocking version, consider calling this method from a separate thread.
sourceDir | Source directory path |
destDir | Destination directory path |
Exception |
|
static |
Move a file. NOTE: for a non-blocking version, consider calling this method from a separate thread.
sourceFile | Source file path |
destFile | Destination file path |
Exception |
|
static |
Opens a file with the OS default application. NOTE: only works for standalone platforms.
file | File path |
Exception |
|
static |
Reads the bytes of a file.
path | Path to the file |
Exception |
|
static |
Reads the bytes of a file asynchronously.
path | Path to the file |
Exception |
|
static |
Reads all lines of text from a file.
path | Path to the file |
encoding | Encoding of the text (optional, default: UTF8) |
Exception |
|
static |
Reads all lines of text from a file asynchronously.
path | Path to the file |
encoding | Encoding of the text (optional, default: UTF8) |
Exception |
|
static |
Reads the text of a file.
path | Path to the file |
encoding | Encoding of the text (optional, default: UTF8) |
Exception |
|
static |
Reads the text of a file asynchronously.
path | Path to the file |
encoding | Encoding of the text (optional, default: UTF8) |
Exception |
|
static |
Renames a file or directory.
path | Path to the file/directory |
newName | New name for the file/directory |
Exception |
|
static |
Renames a directory in a path.
path | Path to the directory |
newName | New name for the directory |
Exception |
|
static |
Renames a file in a path.
path | Path to the file |
newName | New name for the file |
Exception |
|
static |
Shows the location of a file or directory in OS file explorer. NOTE: only works on standalone platforms.
path | Path to the file/directory |
Exception |
|
static |
Validates a given file.
path | File to validate |
removeInvalidChars | Removes invalid characters in the file name (optional, default: true) |
ArgumentNullException |
|
static |
Validates a given path and add missing slash.
path | Path to validate |
addEndDelimiter | Add delimiter at the end of the path (optional, default: true) |
preserveFile | Preserves a given file in the path (optional, default: true) |
removeInvalidChars | Removes invalid characters in the path name (optional default: true) |
ArgumentNullException |
|
static |
Writes bytes to a file.
destFile | Destination file path |
data | Byte-content to write |
Exception |
|
static |
Writes bytes to a file asynchronously.
destFile | Destination file path |
data | Byte-content to write |
Exception |
|
static |
Writes all lines of text to a file.
destFile | Destination file path |
lines | Array of text lines to write |
encoding | Encoding of the text (optional, default: UTF8) |
Exception |
|
static |
Writes all lines of text to a file asynchronously.
destFile | Destination file path |
lines | Array of text lines to write |
encoding | Encoding of the text (optional, default: UTF8) |
Exception |
|
static |
Writes text to a file.
destFile | Destination file path |
text | Text-content to write |
encoding | Encoding of the text (optional, default: UTF8) |
Exception |
|
static |
Writes text to a file asynchronously.
destFile | Destination file path |
text | Text-content to write |
encoding | Encoding of the text (optional, default: UTF8) |
Exception |
|
staticget |
Returns the current directory.
|
staticget |
Returns a temporary directory.
|
staticget |
Returns a temporary file.
|
staticget |
Returns the temporary directory path.