Class ProgramFileUtility
- Namespace
- Songhay
- Assembly
- SonghayCore.dll
A few static helper members for System.IO.
public static class ProgramFileUtility
- Inheritance
-
ProgramFileUtility
- Inherited Members
Methods
CountParentDirectoryChars(string?)
Counts the parent directory chars.
public static int CountParentDirectoryChars(string? path)
Parameters
path
stringThe path.
Returns
Remarks
This method is useful when running GetParentDirectory(string?, int).
WARNING: call NormalizePath(string?) to prevent incorrectly returning 0
in cross-platform scenarios.
FindParentDirectory(string?, string?, int)
Finds the parent directory.
public static string? FindParentDirectory(string? path, string? parentName, int levels)
Parameters
Returns
FindParentDirectoryInfo(string?, string?, int)
Finds the parent DirectoryInfo.
public static DirectoryInfo? FindParentDirectoryInfo(string? path, string? parentName, int levels)
Parameters
Returns
GetCombinedPath(string?, string?)
Combines path and root based on the ambient value of DirectorySeparatorChar of the current OS.
public static string GetCombinedPath(string? root, string? path)
Parameters
Returns
Remarks
For detail, see: 📚 https://github.com/BryanWilhite/SonghayCore/issues/14 📚 https://github.com/BryanWilhite/SonghayCore/issues/32 📚 https://github.com/BryanWilhite/SonghayCore/issues/97
GetCombinedPath(string?, string?, bool)
Combines path and root based on the ambient value of DirectorySeparatorChar of the current OS.
public static string GetCombinedPath(string? root, string? path, bool fileIsExpected)
Parameters
root
stringThe root.
path
stringThe path.
fileIsExpected
boolwhen
true
will throw FileNotFoundException when combined path is not of a file; otherwise will throw DirectoryNotFoundException when combined path is not a directory
Returns
Remarks
For detail, see: 📚 https://github.com/BryanWilhite/SonghayCore/issues/14 📚 https://github.com/BryanWilhite/SonghayCore/issues/32 📚 https://github.com/BryanWilhite/SonghayCore/issues/97
GetEncodedString(string?)
Gets the UTF-8 encoded string from.
public static string GetEncodedString(string? utf16Value)
Parameters
utf16Value
stringThe raw value.
Returns
GetEncodedString(string?, Encoding?)
public static string GetEncodedString(string? utf16Value, Encoding? outputEncoding)
Parameters
Returns
Remarks
Unicode encoding is the UTF-16 encoding of strings in .NET. See: https://docs.microsoft.com/en-us/dotnet/api/system.text.unicodeencoding
GetParentDirectory(string?, int)
Gets the parent directory.
public static string? GetParentDirectory(string? path, int levels)
Parameters
Returns
Remarks
A recursive wrapper for GetParent(string).
GetParentDirectoryInfo(string?, int)
Gets the parent DirectoryInfo.
public static DirectoryInfo? GetParentDirectoryInfo(string? path, int levels)
Parameters
Returns
Remarks
A recursive wrapper for GetParent(string).
GetRelativePath(string?)
Gets the relative path from the specified file segment
without leading dots (.
) or DirectorySeparatorChar chars.
public static string? GetRelativePath(string? fileSegment)
Parameters
fileSegment
stringThe file segment.
Returns
Remarks
This method is the equivalent of calling:
IsForwardSlashSystem()
Returns true
when the current OS
uses forward-slash (/
) paths or not.
public static bool IsForwardSlashSystem()
Returns
NormalizePath(string?)
Normalizes the specified path with respect to the ambient value of DirectorySeparatorChar.
public static string? NormalizePath(string? path)
Parameters
path
stringThe path.
Returns
ReadZipArchiveEntries(FileInfo?, Action<string>?)
Read zip archive entries.
public static void ReadZipArchiveEntries(FileInfo? archiveInfo, Action<string>? fileAction)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
fileAction
Action<string>The action to take per text file.
Remarks
Use entriesProjector
for any filtering or sorting.
ReadZipArchiveEntries(FileInfo?, Action<string>?, Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>>?)
Read zip archive entries.
public static void ReadZipArchiveEntries(FileInfo? archiveInfo, Action<string>? fileAction, Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>>? entriesProjector)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
fileAction
Action<string>The action to take per text file.
entriesProjector
Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>>The entries projector for LINQ filtering/sorting.
Remarks
Use entriesProjector
for any filtering or sorting.
ReadZipArchiveEntriesByLine(FileInfo?, Action<int, string>?)
Read zip archive entries as strings, line by line.
public static void ReadZipArchiveEntriesByLine(FileInfo? archiveInfo, Action<int, string>? lineAction)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
lineAction
Action<int, string>The action to take per text file line.
Remarks
This member is designed for compressed text documents that are too large to load into memory.
The fileAction
includes the line number and the current line.
ReadZipArchiveEntriesByLine(FileInfo?, Action<int, string>?, Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>>?)
Read zip archive entries as strings, line by line.
public static void ReadZipArchiveEntriesByLine(FileInfo? archiveInfo, Action<int, string>? lineAction, Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>>? entriesProjector)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
lineAction
Action<int, string>The action to take per text file line.
entriesProjector
Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>>The entries projector for LINQ filtering/sorting.
Remarks
This member is designed for compressed text documents that are too large to load into memory.
The fileAction
includes the line number and the current line.
RemoveBackslashPrefixes(string?)
Removes conventional Directory prefixes
for relative paths, e.g. ..</code> or
.</code>
public static string? RemoveBackslashPrefixes(string? path)
Parameters
path
stringThe path.
Returns
RemoveConventionalPrefixes(string?)
Removes conventional Directory prefixes
for relative paths based on the ambient value
of DirectorySeparatorChar.
public static string? RemoveConventionalPrefixes(string? path)
Parameters
path
stringThe path.
Returns
RemoveForwardslashPrefixes(string?)
Removes conventional Directory prefixes
for relative paths, e.g. ../
or ./
.
public static string? RemoveForwardslashPrefixes(string? path)
Parameters
path
stringThe path.
Returns
TrimLeadingDirectorySeparatorChars(string?)
Trims the leading directory separator chars.
public static string? TrimLeadingDirectorySeparatorChars(string? path)
Parameters
path
stringThe path.
Returns
Remarks
Trims leading AltDirectorySeparatorChar and/or DirectorySeparatorChar, formatting relative paths for Combine(string, string).
UseZipArchive(FileInfo?, Action<ZipArchive?>?)
Centralizes the use of ZipArchive in Read.
public static void UseZipArchive(FileInfo? archiveInfo, Action<ZipArchive?>? archiveAction)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
archiveAction
Action<ZipArchive>The action to take for the ZIP archive in use.
UseZipArchive(FileInfo?, Action<ZipArchive?>?, ZipArchiveMode)
Centralizes the use of ZipArchive
public static void UseZipArchive(FileInfo? archiveInfo, Action<ZipArchive?>? archiveAction, ZipArchiveMode zipArchiveMode)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
archiveAction
Action<ZipArchive>The action to take for the ZIP archive in use.
zipArchiveMode
ZipArchiveModeThe ZipArchiveMode.
UseZipArchiveEntries(FileInfo?, Action<ReadOnlyCollection<ZipArchiveEntry>>?)
Centralizes the use of ReadOnlyCollection<T>.
public static void UseZipArchiveEntries(FileInfo? archiveInfo, Action<ReadOnlyCollection<ZipArchiveEntry>>? entriesAction)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
entriesAction
Action<ReadOnlyCollection<ZipArchiveEntry>>The action to take for ZIP archive entries.
UseZipArchiveEntries(FileInfo?, Action<ReadOnlyCollection<ZipArchiveEntry>>?, Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>>?)
Centralizes the use of ReadOnlyCollection<T>.
public static void UseZipArchiveEntries(FileInfo? archiveInfo, Action<ReadOnlyCollection<ZipArchiveEntry>>? entriesAction, Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>>? entriesProjector)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
entriesAction
Action<ReadOnlyCollection<ZipArchiveEntry>>The action to take for ZIP archive entries.
entriesProjector
Func<ReadOnlyCollection<ZipArchiveEntry>, IEnumerable<ZipArchiveEntry>>The entries projector for LINQ filtering/sorting.
WriteZipArchiveEntry(FileInfo?, FileInfo)
Write zip archive entry with Optimal.
public static void WriteZipArchiveEntry(FileInfo? archiveInfo, FileInfo fileInfo)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
fileInfo
FileInfoThe file information for writing the entry.
WriteZipArchiveEntry(FileInfo?, FileInfo, CompressionLevel)
Write zip archive entry.
public static void WriteZipArchiveEntry(FileInfo? archiveInfo, FileInfo fileInfo, CompressionLevel compressionLevel)
Parameters
archiveInfo
FileInfoThe ZIP archive FileInfo.
fileInfo
FileInfoThe file information for writing the entry.
compressionLevel
CompressionLevelThe CompressionLevel.