Class FileUtil
Utility to manage files.
public static class FileUtil
- Inheritance
-
FileUtil
- Inherited Members
Methods
CopyDirectory(string, string)
Copies a directory and all its contents to a destination folder.
public static void CopyDirectory(string sourceFolder, string destFolder)
Parameters
CreateWithDirectoryAndGetFileStream(string)
Creates or loads a file with directory.
public static FileStream CreateWithDirectoryAndGetFileStream(string filePath)
Parameters
filePath
stringfile path
Returns
- FileStream
file stream
CreateWithDirectoryIfNotExisted(string)
public static bool CreateWithDirectoryIfNotExisted(string filePath)
Parameters
filePath
string
Returns
- bool
true if file created.
EnsureDirectory(string)
Ensures that the specified directory exists, creating it if necessary.
public static void EnsureDirectory(string directory)
Parameters
directory
stringThe directory path to ensure exists.
GetAbsentPath(string, string)
Gets a path that doesn't exist by appending a number to the base path.
public static string GetAbsentPath(string pathWithoutExtension, string extension)
Parameters
Returns
- string
A path that doesn't exist.
GetAbsentRelPath(string, string, string)
Gets a relative path that doesn't exist by appending a number to the base path.
public static string GetAbsentRelPath(string baseDirectory, string relPathWithoutExtension, string extension)
Parameters
baseDirectory
stringThe base directory.
relPathWithoutExtension
stringThe relative path without extension.
extension
stringThe file extension.
Returns
- string
A relative path that doesn't exist.
GetDescendentPath(string)
Get descendent path if the path
is descendent of current path; otherwise
return path
.
public static string GetDescendentPath(string path)
Parameters
path
stringpath
Returns
- string
descendent path if the
path
is descendent of current path; otherwise returnpath
GetFileSizeString(FileInfo, string)
Gets a formatted string representing the file size.
public static string GetFileSizeString(this FileInfo fileInfo, string format = "{0,6:###.00} {1,-2:##}")
Parameters
Returns
- string
A formatted string representing the file size.
IsBinaryFile(string)
Determines if a file is likely to be a binary file by checking for control characters.
public static bool IsBinaryFile(string filePath)
Parameters
filePath
stringPath to the file to check
Returns
- bool
True if the file appears to be binary, false otherwise
ReadAllTextWithFileShareAsync(string)
Reads all text from a file with file sharing enabled.
public static Task<string> ReadAllTextWithFileShareAsync(string filePath)
Parameters
filePath
stringThe path of the file to read.
Returns
ToIndexedFile(IEnumerable<string>)
Converts a collection of file paths to a collection of indexed files.
public static IEnumerable<IndexedFile> ToIndexedFile(this IEnumerable<string> files)
Parameters
files
IEnumerable<string>The collection of file paths.
Returns
- IEnumerable<IndexedFile>
A collection of indexed files.