Appearance
FileHelper Class
Definition
Provides helper methods for common file and directory operations, including comparison, copying, cache-busting fingerprints, embedded resource loading, and non-locking read helpers.
- Namespace:
JASE.IO - Assembly:
JASE.dll
Methods
| Name | Description |
|---|---|
bool AppendAllBytes(string path, byte[] bytes) | Appends the specified bytes to a file, creating it if it does not exist. |
bool CompareDirectories(string dir1, string dir2, string fileMask = null, SearchOption searchOption = null) | Compares two directories for equality based on a file mask and search option. |
bool CompareFiles(FileInfo file1, FileInfo file2) | Compares two files for byte-for-byte equality. |
bool CompareFiles(string file1, string file2) | Compares two files for byte-for-byte equality. |
bool ConcatFiles(IEnumerable<string> files, string destination) | Concatenates the contents of one or more source files into a destination file. |
void Copy(string sourceDirectory, string targetDirectory, bool preserveTimestamps = null) | Copies the contents of one directory to another, optionally preserving timestamps. |
void CopyAll(DirectoryInfo source, DirectoryInfo target, bool preserveTimestamps = null) | Recursively copies all files and subdirectories from a source directory to a target directory. |
bool DeleteDirectoryFiles(string directory, bool createIfNotExist = null) | Deletes all files in the specified directory, optionally creating the directory if it does not exist. |
bool DeleteFiles(IEnumerable<string> files) | Deletes the specified files. |
string Fingerprint(string path, bool useMinified = null) | Adds a virtual cache-busting fingerprint to a static file path. |
string GetAppRelativePath(string input, bool trimLeading = null) | Returns a file path relative to the application root. |
Encoding GetFileEncoding(Stream stream) | Attempts to detect the text encoding of a file from a stream by inspecting its initial bytes. |
Encoding GetFileEncoding(string filename) | Attempts to detect the text encoding of the specified file. |
string GetMinifiedFilename(FileInfo fi) | Resolves a minified or production variant of the specified file, if available. |
string GetMinifiedFilename(string path) | Resolves a minified or production variant of the specified file path, if available. |
byte[] ReadAllBytesNoLock(FileInfo fileInfo) | Reads all bytes from a file without holding a long-term exclusive lock. |
byte[] ReadAllBytesNoLock(string filename) | Reads all bytes from a file without holding a long-term exclusive lock. |
string[] ReadAllLinesNoLock(FileInfo fileInfo) | Reads all lines from a file without holding a long-term exclusive lock. |
string[] ReadAllLinesNoLock(string filename) | Reads all lines from a file without holding a long-term exclusive lock. |
string ReadAllTextNoLock(FileInfo fileInfo) | Reads all text from a file without holding a long-term exclusive lock. |
string ReadAllTextNoLock(string filename) | Reads all text from a file without holding a long-term exclusive lock. |
byte[] ReadAssemblyFile(Assembly assembly, string filename, bool prependAssembly = null) | Returns the contents of an embedded assembly resource as a byte array. |
string ReadAssemblyTextFile(Assembly assembly, string filename, bool prependAssembly = null) | Returns the contents of an embedded assembly resource as a string. |
IEnumerable<string> ReadLinesFromFile(string filename) | Lazily reads a file line-by-line. |
string ResolveDomainPath(string filename) | Resolves a file path relative to the application domain path if necessary. |
string ResolveFileName(string filename) | Resolves a file path by probing application-specific locations. |
string ResolvePath(string path) | Resolves a directory path by probing application-specific locations. |
bool SetAttribute(string path, FileAttributes attrib, bool recurseDirectory = null) | Sets a file attribute on the specified file or, optionally, on all files within a directory tree. |
string StreamToText(Stream stream) | Reads all text from a stream to a string. |
string StreamToText(Stream stream, out Encoding encoding) | Reads all text from a stream to a string and reports the detected encoding. |