Table of Contents

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 string

The path.

Returns

int

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

path string

The path.

parentName string

Name of the parent.

levels int

The levels.

Returns

string

FindParentDirectoryInfo(string?, string?, int)

Finds the parent DirectoryInfo.

public static DirectoryInfo? FindParentDirectoryInfo(string? path, string? parentName, int levels)

Parameters

path string

The path.

parentName string

Name of the parent.

levels int

The levels.

Returns

DirectoryInfo

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

root string

The root.

path string

The path.

Returns

string

Remarks

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 string

The root.

path string

The path.

fileIsExpected bool

when true will throw FileNotFoundException when combined path is not of a file; otherwise will throw DirectoryNotFoundException when combined path is not a directory

Returns

string

Remarks

GetEncodedString(string?)

Gets the UTF-8 encoded string from.

public static string GetEncodedString(string? utf16Value)

Parameters

utf16Value string

The raw value.

Returns

string

GetEncodedString(string?, Encoding?)

Gets the encoded string from its default Unicode encoding.

public static string GetEncodedString(string? utf16Value, Encoding? outputEncoding)

Parameters

utf16Value string

The raw value.

outputEncoding Encoding

The output encoding.

Returns

string

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

path string

The path.

levels int

The levels.

Returns

string

Remarks

A recursive wrapper for GetParent(string).

GetParentDirectoryInfo(string?, int)

Gets the parent DirectoryInfo.

public static DirectoryInfo? GetParentDirectoryInfo(string? path, int levels)

Parameters

path string

The path.

levels int

The levels.

Returns

DirectoryInfo

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 string

The file segment.

Returns

string

Remarks

IsForwardSlashSystem()

Returns true when the current OS uses forward-slash (/) paths or not.

public static bool IsForwardSlashSystem()

Returns

bool

NormalizePath(string?)

Normalizes the specified path with respect to the ambient value of DirectorySeparatorChar.

public static string? NormalizePath(string? path)

Parameters

path string

The path.

Returns

string

ReadZipArchiveEntries(FileInfo?, Action<string>?)

Read zip archive entries.

public static void ReadZipArchiveEntries(FileInfo? archiveInfo, Action<string>? fileAction)

Parameters

archiveInfo FileInfo

The 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 FileInfo

The 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 FileInfo

The 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 FileInfo

The 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 string

The path.

Returns

string

RemoveConventionalPrefixes(string?)

Removes conventional Directory prefixes for relative paths based on the ambient value
of DirectorySeparatorChar.

public static string? RemoveConventionalPrefixes(string? path)

Parameters

path string

The path.

Returns

string

RemoveForwardslashPrefixes(string?)

Removes conventional Directory prefixes for relative paths, e.g. ../ or ./.

public static string? RemoveForwardslashPrefixes(string? path)

Parameters

path string

The path.

Returns

string

TrimLeadingDirectorySeparatorChars(string?)

Trims the leading directory separator chars.

public static string? TrimLeadingDirectorySeparatorChars(string? path)

Parameters

path string

The path.

Returns

string

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 FileInfo

The 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 FileInfo

The ZIP archive FileInfo.

archiveAction Action<ZipArchive>

The action to take for the ZIP archive in use.

zipArchiveMode ZipArchiveMode

The ZipArchiveMode.

UseZipArchiveEntries(FileInfo?, Action<ReadOnlyCollection<ZipArchiveEntry>>?)

Centralizes the use of ReadOnlyCollection<T>.

public static void UseZipArchiveEntries(FileInfo? archiveInfo, Action<ReadOnlyCollection<ZipArchiveEntry>>? entriesAction)

Parameters

archiveInfo FileInfo

The 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 FileInfo

The 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 FileInfo

The ZIP archive FileInfo.

fileInfo FileInfo

The 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 FileInfo

The ZIP archive FileInfo.

fileInfo FileInfo

The file information for writing the entry.

compressionLevel CompressionLevel

The CompressionLevel.