C# Class CoreTechs.Common.FileSystemExtensions

Datei anzeigen Open project: Core-Techs/Common

Public Methods

Method Description
AreSame ( this a, DirectoryInfo b ) : bool
AreSame ( this a, FileInfo b ) : bool
AttemptOpen ( this file, FileAccess fileAccess = FileAccess.ReadWrite, FileShare fileShare = FileShare.None ) : Attempt

Attempts to open a file. Immediately closes the file if successful. Swallows (but returns) any exception encountered while trying to open the file.

ComputeFileHash ( this fileInfo, HashAlgorithm algorithm = null ) : string
ComputeHash ( this stream, HashAlgorithm algorithm = null ) : byte[]
Contains ( this dir, FileSystemInfo other ) : bool

Determines if the directory contains the other directory or file at any depth.

ContainsDirectly ( this dir, FileSystemInfo other ) : bool

Determines if the directory directly contains the other directory or file.

ConvertToString ( this bytes ) : string
CreateFileSystemInfoFromPath ( this path ) : FileSystemInfo
EnsureExists ( this dir ) : DirectoryInfo
EnumerateBytes ( this file ) : IEnumerable
EnumeratePathDownFromRoot ( this source ) : IEnumerable

Yields each part of the path, ordered from the root to the item.

EnumeratePathUpToRoot ( this source ) : IEnumerable

Yields each part of the path, ordered from the item to the root.

GetFile ( this directory, string file ) : FileInfo
GetParentDirectory ( this fileSystemInfo ) : DirectoryInfo
GetPath ( this specialFolder, Environment option = Environment.SpecialFolderOption.None ) : string
GetRelativePathFrom ( this to, FileSystemInfo from ) : string
GetRelativePathTo ( this from, FileSystemInfo to ) : string
GetSubDirectory ( this directory ) : DirectoryInfo
GetUnchangedFiles ( this source, System.TimeSpan interval, CancellationToken cancellationToken = default(CancellationToken) ) : System.IO.FileInfo[]

Returns files that haven't changed over a period of time.

IsContainedDirectlyWithin ( this fileOrDirectory, DirectoryInfo otherDir ) : bool

Determines if the file or directory is contained directly within the the other directory.

IsContainedWithin ( this fileOrDirectory, DirectoryInfo otherDir ) : bool

Determines if the file or directory is contained within the the other directory at any depth.

IsDirectoryPath ( this path ) : bool
IsFilePath ( this path ) : bool
PollForAllFiles ( this di, System.TimeSpan interval, CancellationToken cancellationToken = default(CancellationToken) ) : System.IO.FileInfo[]

Checks and rechecks a directory and all sub-directories for files. Only returns files that haven't changed between checks.

PollForFiles ( this di, System.TimeSpan interval, string searchPattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly, CancellationToken cancellationToken = default(CancellationToken) ) : System.IO.FileInfo[]

Checks and rechecks a directory for files. Only returns files that haven't changed between checks.

WhereCanOpen ( this files ) : IEnumerable

Method Details

AreSame() public static method

public static AreSame ( this a, DirectoryInfo b ) : bool
a this
b System.IO.DirectoryInfo
return bool

AreSame() public static method

public static AreSame ( this a, FileInfo b ) : bool
a this
b System.IO.FileInfo
return bool

AttemptOpen() public static method

Attempts to open a file. Immediately closes the file if successful. Swallows (but returns) any exception encountered while trying to open the file.
public static AttemptOpen ( this file, FileAccess fileAccess = FileAccess.ReadWrite, FileShare fileShare = FileShare.None ) : Attempt
file this The file to attempt to open.
fileAccess FileAccess The access required to open the file. Defaults to ReadWrite.
fileShare FileShare The access granted to others trying to manipulate the file. Defaults to none.
return Attempt

ComputeFileHash() public static method

public static ComputeFileHash ( this fileInfo, HashAlgorithm algorithm = null ) : string
fileInfo this
algorithm System.Security.Cryptography.HashAlgorithm
return string

ComputeHash() public static method

public static ComputeHash ( this stream, HashAlgorithm algorithm = null ) : byte[]
stream this
algorithm System.Security.Cryptography.HashAlgorithm
return byte[]

Contains() public static method

Determines if the directory contains the other directory or file at any depth.
public static Contains ( this dir, FileSystemInfo other ) : bool
dir this
other System.IO.FileSystemInfo
return bool

ContainsDirectly() public static method

Determines if the directory directly contains the other directory or file.
public static ContainsDirectly ( this dir, FileSystemInfo other ) : bool
dir this
other System.IO.FileSystemInfo
return bool

ConvertToString() public static method

public static ConvertToString ( this bytes ) : string
bytes this
return string

CreateFileSystemInfoFromPath() public static method

public static CreateFileSystemInfoFromPath ( this path ) : FileSystemInfo
path this
return System.IO.FileSystemInfo

EnsureExists() public static method

public static EnsureExists ( this dir ) : DirectoryInfo
dir this
return System.IO.DirectoryInfo

EnumerateBytes() public static method

public static EnumerateBytes ( this file ) : IEnumerable
file this
return IEnumerable

EnumeratePathDownFromRoot() public static method

Yields each part of the path, ordered from the root to the item.
public static EnumeratePathDownFromRoot ( this source ) : IEnumerable
source this
return IEnumerable

EnumeratePathUpToRoot() public static method

Yields each part of the path, ordered from the item to the root.
public static EnumeratePathUpToRoot ( this source ) : IEnumerable
source this
return IEnumerable

GetFile() public static method

public static GetFile ( this directory, string file ) : FileInfo
directory this
file string
return System.IO.FileInfo

GetParentDirectory() public static method

public static GetParentDirectory ( this fileSystemInfo ) : DirectoryInfo
fileSystemInfo this
return System.IO.DirectoryInfo

GetPath() public static method

public static GetPath ( this specialFolder, Environment option = Environment.SpecialFolderOption.None ) : string
specialFolder this
option Environment
return string

GetRelativePathFrom() public static method

public static GetRelativePathFrom ( this to, FileSystemInfo from ) : string
to this
from System.IO.FileSystemInfo
return string

GetRelativePathTo() public static method

public static GetRelativePathTo ( this from, FileSystemInfo to ) : string
from this
to System.IO.FileSystemInfo
return string

GetSubDirectory() public static method

public static GetSubDirectory ( this directory ) : DirectoryInfo
directory this
return System.IO.DirectoryInfo

GetUnchangedFiles() public static method

Returns files that haven't changed over a period of time.
public static GetUnchangedFiles ( this source, System.TimeSpan interval, CancellationToken cancellationToken = default(CancellationToken) ) : System.IO.FileInfo[]
source this Files to check.
interval System.TimeSpan Time to wait between checking the files.
cancellationToken System.Threading.CancellationToken Token to cancel the wait between checks.
return System.IO.FileInfo[]

IsContainedDirectlyWithin() public static method

Determines if the file or directory is contained directly within the the other directory.
public static IsContainedDirectlyWithin ( this fileOrDirectory, DirectoryInfo otherDir ) : bool
fileOrDirectory this
otherDir System.IO.DirectoryInfo
return bool

IsContainedWithin() public static method

Determines if the file or directory is contained within the the other directory at any depth.
public static IsContainedWithin ( this fileOrDirectory, DirectoryInfo otherDir ) : bool
fileOrDirectory this
otherDir System.IO.DirectoryInfo
return bool

IsDirectoryPath() public static method

public static IsDirectoryPath ( this path ) : bool
path this
return bool

IsFilePath() public static method

public static IsFilePath ( this path ) : bool
path this
return bool

PollForAllFiles() public static method

Checks and rechecks a directory and all sub-directories for files. Only returns files that haven't changed between checks.
public static PollForAllFiles ( this di, System.TimeSpan interval, CancellationToken cancellationToken = default(CancellationToken) ) : System.IO.FileInfo[]
di this The directory to check.
interval System.TimeSpan The time between checking for files.
cancellationToken System.Threading.CancellationToken Token to cancel the wait between checks.
return System.IO.FileInfo[]

PollForFiles() public static method

Checks and rechecks a directory for files. Only returns files that haven't changed between checks.
public static PollForFiles ( this di, System.TimeSpan interval, string searchPattern = "*", SearchOption searchOption = SearchOption.TopDirectoryOnly, CancellationToken cancellationToken = default(CancellationToken) ) : System.IO.FileInfo[]
di this The directory to check.
interval System.TimeSpan The time between checking for files.
searchPattern string The search pattern.
searchOption SearchOption The search options.
cancellationToken System.Threading.CancellationToken Token to cancel the wait between checks.
return System.IO.FileInfo[]

WhereCanOpen() public static method

public static WhereCanOpen ( this files ) : IEnumerable
files this
return IEnumerable