C# Класс ClrPlus.Platform.FilesystemExtensions

Functions related to handling things regarding files and filesystems.
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
OriginalTempFolder string

Открытые методы

Метод Описание
CanonicalizePath ( this path, bool IsPotentiallyRelativePath = true ) : string

This takes a string that is representative of a filename and tries to create a path that can be considered the 'canonical' path. path on drives that are mapped as remote shares are rewritten as their \\server\share\path

CanonicalizePathIfLocalAndExists ( this filename ) : string
CanonicalizePathWithWildcards ( this path ) : string

cleans up a path if it is a filesystem path, uri or wildcard. returns the original unmodified path if it is not.

ChangeFileExtensionTo ( this currentFilename, string newExtension ) : string

Changes the file extension to another extension.

CreateWritableWorkingCopy ( this filename ) : string

This makes a temporary copy of a file that we can work with.

DirectoryEnumerateFilesSmarter ( this path, SearchOption searchOption ) : IEnumerable
DirectoryEnumerateFilesSmarter ( this path, string searchPattern, SearchOption searchOption ) : IEnumerable

Enumerates files in a directory, smarter than Direcotry.EnumerateFiles (ie, doesn't throw, when it can't access something)

DirectoryExistsAndIsAccessible ( this path ) : bool

Directories the exists and is accessible.

EnsureFileIsLocal ( this filename, string localFolder = null ) : string
FileIsLocalAndExists ( this filename ) : bool
FindFilesSmarter ( this pathMask, string subpathMask = null ) : IEnumerable

A front end to DirectoryEnumerateFilesSmarter that allows for wildcards in the path or serarch mask (and expands it out to a full path first.) it also constrains the path as much as possible to keep from enumerating directories that will never match files.

FindFilesSmarter ( this pathMasks ) : IEnumerable

finds matches for a collection of filenames using FindFilesSmarter (above)

FindFilesSmarterComplex ( this pathMask, string pathPrefix = null ) : IEnumerable

always call IsWildcardMatch with a prefix!!!!

FindFilesSmarterComplex ( this pathMasks, string pathPrefix = null ) : IEnumerable
FixFilepathSlashes ( this filepath ) : string

Replaces Unix style file path separators (/) with Windows style (\).

FormatFilename ( this filename ) : string

Generates a filename on a somewhat different template.

{date} - the current date (y-m-d) {date-long} - the date in long format {time} - the current time (Hh:mm:ss) {time-long} - the current time in long fmt {ticks} - the current timestamp as tics {counter} - a running counter

GenerateTemplatedFilename ( this filename, string filenameHint ) : string

Generates a filename based of a template that can contain many different values

{filename} - substitutes for the original filename, no extension {ext} original extension {folder} - original folder {subfolder} - original folder without leading / {count} - a running count of the files downloaded. {date} - the current date (y-m-d) {date-long} - the date in long format {time} - the current time (Hh:mm:ss) {time-long} - the current time in long fmt {ticks} - the current timestamp as tics

GenerateTemporaryFilename ( this filename ) : string
GetAllCustomFilePaths ( this filename, string currentDirectory ) : IEnumerable
GetCustomFilePath ( this filename, string currentDirectory = null ) : string
GetCustomFilePathOrWalkUp ( this filename, string currentDirectory = null ) : string
GetDirectoryStack ( this currentDirectory ) : IEnumerable
GetFileInTempFolder ( this filename ) : string
GetFileMD5 ( this filename ) : string

Returns the MD5 Hash of a file as an uppercase hex string

GetFileSHA1 ( this filename ) : string
GetFullPath ( this path ) : string

Returns the full path of a string. Short circuts the process if the string is a known full path already. (ie, the result of a preivious GetFullPath())

GetMinimalPaths ( this paths ) : IEnumerable
GetMinimalPathsToDictionary ( this paths ) : string>.IDictionary
GetSubPath ( this parentPath, string childPath ) : string

Gets the portion of the childPath that is a sub path of the parentPath Returns string.Empty if the childPath is not a sub path of the parent.

IsFolderEmpty ( string foldername ) : bool?
IsSimpleSubPath ( this path ) : bool

Tells whether a given path is a simple subpath. A simple subpath has the following characteristics: - No drive letter or colon - Does not start with a slash - Does not contain any path part sections consisting of just "." or ".." - Does not contain wildcards

IsSubPath ( this rootPath, string childPath ) : bool

Determines if the childPath is a sub path of the rootPath

MarkFileTemporary ( this filename ) : string
NameWithoutExt ( this fi ) : string

Gets the name of a file minus it's extension, ie: if the file name is "test.exe", returns "test".

NormalizePath ( this path ) : string

Translates paths starting with \??\ to regular paths.

ReadAllBytesFromFile ( this ms, string path ) : void

Reads the contents of a file into a memory stream.

RelativePathTo ( this currentDirectory, string pathToMakeRelative ) : string

Gets the relative path between two paths.

RemoveDeadLnks ( string folder ) : void
RemoveEssentiallyEmptyFolders ( string folderName ) : bool
RemoveInvalidSymlinks ( string directory = null, int maxdepth = 3 ) : void
RemoveTemporaryFiles ( ) : void
ResetTempFolder ( ) : void
TryHardToDelete ( this location ) : void
TryHardToMakeFileWriteable ( this filename ) : void

This makes sure a file is writable by moving the original, copying this one back then deleting the original (or at least tryinghardtodelete the original). This allows us to modify locked files in place.

TryToHandlePendingRenames ( bool force = false ) : void
WalkUpPath ( this filename, string currentDirectory = null ) : string
WalkUpPaths ( this filenames, string currentDirectory = null ) : string
Write ( this fileStream, byte data ) : int

Writes the whole byte array to a filestream. (lazy!)

WriteAllBytesToFile ( this ms, string path ) : void

Writes all bytes from the contents of a memorystream to file (as a binary file).

Приватные методы

Метод Описание
FilesystemExtensions ( ) : System
GetNextPart ( this path ) : string>.Tuple

Gets the next part. Note: Make Eric document this?

Описание методов

CanonicalizePath() публичный статический Метод

This takes a string that is representative of a filename and tries to create a path that can be considered the 'canonical' path. path on drives that are mapped as remote shares are rewritten as their \\server\share\path
public static CanonicalizePath ( this path, bool IsPotentiallyRelativePath = true ) : string
path this
IsPotentiallyRelativePath bool
Результат string

CanonicalizePathIfLocalAndExists() публичный статический Метод

public static CanonicalizePathIfLocalAndExists ( this filename ) : string
filename this
Результат string

CanonicalizePathWithWildcards() публичный статический Метод

cleans up a path if it is a filesystem path, uri or wildcard. returns the original unmodified path if it is not.
public static CanonicalizePathWithWildcards ( this path ) : string
path this
Результат string

ChangeFileExtensionTo() публичный статический Метод

Changes the file extension to another extension.
public static ChangeFileExtensionTo ( this currentFilename, string newExtension ) : string
currentFilename this The current filename.
newExtension string The new extension.
Результат string

CreateWritableWorkingCopy() публичный статический Метод

This makes a temporary copy of a file that we can work with.
public static CreateWritableWorkingCopy ( this filename ) : string
filename this
Результат string

DirectoryEnumerateFilesSmarter() публичный статический Метод

public static DirectoryEnumerateFilesSmarter ( this path, SearchOption searchOption ) : IEnumerable
path this
searchOption SearchOption
Результат IEnumerable

DirectoryEnumerateFilesSmarter() публичный статический Метод

Enumerates files in a directory, smarter than Direcotry.EnumerateFiles (ie, doesn't throw, when it can't access something)
public static DirectoryEnumerateFilesSmarter ( this path, string searchPattern, SearchOption searchOption ) : IEnumerable
path this The path.
searchPattern string The search pattern.
searchOption SearchOption The search option.
Результат IEnumerable

DirectoryExistsAndIsAccessible() публичный статический Метод

Directories the exists and is accessible.
public static DirectoryExistsAndIsAccessible ( this path ) : bool
path this The path.
Результат bool

EnsureFileIsLocal() публичный статический Метод

public static EnsureFileIsLocal ( this filename, string localFolder = null ) : string
filename this
localFolder string
Результат string

FileIsLocalAndExists() публичный статический Метод

public static FileIsLocalAndExists ( this filename ) : bool
filename this
Результат bool

FindFilesSmarter() публичный статический Метод

A front end to DirectoryEnumerateFilesSmarter that allows for wildcards in the path or serarch mask (and expands it out to a full path first.) it also constrains the path as much as possible to keep from enumerating directories that will never match files.
public static FindFilesSmarter ( this pathMask, string subpathMask = null ) : IEnumerable
pathMask this The path mask.
subpathMask string the sub path mask.
Результат IEnumerable

FindFilesSmarter() публичный статический Метод

finds matches for a collection of filenames using FindFilesSmarter (above)
public static FindFilesSmarter ( this pathMasks ) : IEnumerable
pathMasks this The path masks.
Результат IEnumerable

FindFilesSmarterComplex() публичный статический Метод

always call IsWildcardMatch with a prefix!!!!
public static FindFilesSmarterComplex ( this pathMask, string pathPrefix = null ) : IEnumerable
pathMask this
pathPrefix string
Результат IEnumerable

FindFilesSmarterComplex() публичный статический Метод

public static FindFilesSmarterComplex ( this pathMasks, string pathPrefix = null ) : IEnumerable
pathMasks this
pathPrefix string
Результат IEnumerable

FixFilepathSlashes() публичный статический Метод

Replaces Unix style file path separators (/) with Windows style (\).
public static FixFilepathSlashes ( this filepath ) : string
filepath this The filepath.
Результат string

FormatFilename() публичный статический Метод

Generates a filename on a somewhat different template.
{date} - the current date (y-m-d) {date-long} - the date in long format {time} - the current time (Hh:mm:ss) {time-long} - the current time in long fmt {ticks} - the current timestamp as tics {counter} - a running counter
public static FormatFilename ( this filename ) : string
filename this The filename.
Результат string

GenerateTemplatedFilename() публичный статический Метод

Generates a filename based of a template that can contain many different values
{filename} - substitutes for the original filename, no extension {ext} original extension {folder} - original folder {subfolder} - original folder without leading / {count} - a running count of the files downloaded. {date} - the current date (y-m-d) {date-long} - the date in long format {time} - the current time (Hh:mm:ss) {time-long} - the current time in long fmt {ticks} - the current timestamp as tics
public static GenerateTemplatedFilename ( this filename, string filenameHint ) : string
filename this The filename.
filenameHint string The filename hint.
Результат string

GenerateTemporaryFilename() публичный статический Метод

public static GenerateTemporaryFilename ( this filename ) : string
filename this
Результат string

GetAllCustomFilePaths() публичный статический Метод

public static GetAllCustomFilePaths ( this filename, string currentDirectory ) : IEnumerable
filename this
currentDirectory string
Результат IEnumerable

GetCustomFilePath() публичный статический Метод

public static GetCustomFilePath ( this filename, string currentDirectory = null ) : string
filename this
currentDirectory string
Результат string

GetCustomFilePathOrWalkUp() публичный статический Метод

public static GetCustomFilePathOrWalkUp ( this filename, string currentDirectory = null ) : string
filename this
currentDirectory string
Результат string

GetDirectoryStack() публичный статический Метод

public static GetDirectoryStack ( this currentDirectory ) : IEnumerable
currentDirectory this
Результат IEnumerable

GetFileInTempFolder() публичный статический Метод

public static GetFileInTempFolder ( this filename ) : string
filename this
Результат string

GetFileMD5() публичный статический Метод

Returns the MD5 Hash of a file as an uppercase hex string
public static GetFileMD5 ( this filename ) : string
filename this the filename to retrive the hash for
Результат string

GetFileSHA1() публичный статический Метод

public static GetFileSHA1 ( this filename ) : string
filename this
Результат string

GetFullPath() публичный статический Метод

Returns the full path of a string. Short circuts the process if the string is a known full path already. (ie, the result of a preivious GetFullPath())
public static GetFullPath ( this path ) : string
path this The path.
Результат string

GetMinimalPaths() публичный статический Метод

public static GetMinimalPaths ( this paths ) : IEnumerable
paths this
Результат IEnumerable

GetMinimalPathsToDictionary() публичный статический Метод

public static GetMinimalPathsToDictionary ( this paths ) : string>.IDictionary
paths this
Результат string>.IDictionary

GetSubPath() публичный статический Метод

Gets the portion of the childPath that is a sub path of the parentPath Returns string.Empty if the childPath is not a sub path of the parent.
public static GetSubPath ( this parentPath, string childPath ) : string
parentPath this The parent path.
childPath string The child path.
Результат string

IsFolderEmpty() публичный статический Метод

public static IsFolderEmpty ( string foldername ) : bool?
foldername string
Результат bool?

IsSimpleSubPath() публичный статический Метод

Tells whether a given path is a simple subpath. A simple subpath has the following characteristics: - No drive letter or colon - Does not start with a slash - Does not contain any path part sections consisting of just "." or ".." - Does not contain wildcards
public static IsSimpleSubPath ( this path ) : bool
path this the path to check
Результат bool

IsSubPath() публичный статический Метод

Determines if the childPath is a sub path of the rootPath
public static IsSubPath ( this rootPath, string childPath ) : bool
rootPath this The root path.
childPath string The child path.
Результат bool

MarkFileTemporary() публичный статический Метод

public static MarkFileTemporary ( this filename ) : string
filename this
Результат string

NameWithoutExt() публичный статический Метод

Gets the name of a file minus it's extension, ie: if the file name is "test.exe", returns "test".
public static NameWithoutExt ( this fi ) : string
fi this The fi.
Результат string

NormalizePath() публичный статический Метод

Translates paths starting with \??\ to regular paths.
public static NormalizePath ( this path ) : string
path this The path.
Результат string

ReadAllBytesFromFile() публичный статический Метод

Reads the contents of a file into a memory stream.
public static ReadAllBytesFromFile ( this ms, string path ) : void
ms this The ms.
path string The path.
Результат void

RelativePathTo() публичный статический Метод

Gets the relative path between two paths.
public static RelativePathTo ( this currentDirectory, string pathToMakeRelative ) : string
currentDirectory this The current directory.
pathToMakeRelative string The path to make relative.
Результат string

RemoveDeadLnks() публичный статический Метод

public static RemoveDeadLnks ( string folder ) : void
folder string
Результат void

RemoveEssentiallyEmptyFolders() публичный статический Метод

public static RemoveEssentiallyEmptyFolders ( string folderName ) : bool
folderName string
Результат bool

RemoveInvalidSymlinks() публичный статический Метод

public static RemoveInvalidSymlinks ( string directory = null, int maxdepth = 3 ) : void
directory string
maxdepth int
Результат void

RemoveTemporaryFiles() публичный статический Метод

public static RemoveTemporaryFiles ( ) : void
Результат void

ResetTempFolder() публичный статический Метод

public static ResetTempFolder ( ) : void
Результат void

TryHardToDelete() публичный статический Метод

public static TryHardToDelete ( this location ) : void
location this
Результат void

TryHardToMakeFileWriteable() публичный статический Метод

This makes sure a file is writable by moving the original, copying this one back then deleting the original (or at least tryinghardtodelete the original). This allows us to modify locked files in place.
public static TryHardToMakeFileWriteable ( this filename ) : void
filename this
Результат void

TryToHandlePendingRenames() публичный статический Метод

public static TryToHandlePendingRenames ( bool force = false ) : void
force bool
Результат void

WalkUpPath() публичный статический Метод

public static WalkUpPath ( this filename, string currentDirectory = null ) : string
filename this
currentDirectory string
Результат string

WalkUpPaths() публичный статический Метод

public static WalkUpPaths ( this filenames, string currentDirectory = null ) : string
filenames this
currentDirectory string
Результат string

Write() публичный статический Метод

Writes the whole byte array to a filestream. (lazy!)
public static Write ( this fileStream, byte data ) : int
fileStream this The file stream.
data byte The data.
Результат int

WriteAllBytesToFile() публичный статический Метод

Writes all bytes from the contents of a memorystream to file (as a binary file).
public static WriteAllBytesToFile ( this ms, string path ) : void
ms this The ms.
path string The path.
Результат void

Описание свойств

OriginalTempFolder публичное статическое свойство

public static string OriginalTempFolder
Результат string