C# Class ClrPlus.Platform.FilesystemExtensions

Functions related to handling things regarding files and filesystems.
Afficher le fichier Open project: perpetual-motion/clrplus

Méthodes publiques

Свойство Type Description
OriginalTempFolder string

Méthodes publiques

Méthode Description
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).

Private Methods

Méthode Description
FilesystemExtensions ( ) : System
GetNextPart ( this path ) : string>.Tuple

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

Method Details

CanonicalizePath() public static méthode

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
Résultat string

CanonicalizePathIfLocalAndExists() public static méthode

public static CanonicalizePathIfLocalAndExists ( this filename ) : string
filename this
Résultat string

CanonicalizePathWithWildcards() public static méthode

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
Résultat string

ChangeFileExtensionTo() public static méthode

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.
Résultat string

CreateWritableWorkingCopy() public static méthode

This makes a temporary copy of a file that we can work with.
public static CreateWritableWorkingCopy ( this filename ) : string
filename this
Résultat string

DirectoryEnumerateFilesSmarter() public static méthode

public static DirectoryEnumerateFilesSmarter ( this path, SearchOption searchOption ) : IEnumerable
path this
searchOption SearchOption
Résultat IEnumerable

DirectoryEnumerateFilesSmarter() public static méthode

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.
Résultat IEnumerable

DirectoryExistsAndIsAccessible() public static méthode

Directories the exists and is accessible.
public static DirectoryExistsAndIsAccessible ( this path ) : bool
path this The path.
Résultat bool

EnsureFileIsLocal() public static méthode

public static EnsureFileIsLocal ( this filename, string localFolder = null ) : string
filename this
localFolder string
Résultat string

FileIsLocalAndExists() public static méthode

public static FileIsLocalAndExists ( this filename ) : bool
filename this
Résultat bool

FindFilesSmarter() public static méthode

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.
Résultat IEnumerable

FindFilesSmarter() public static méthode

finds matches for a collection of filenames using FindFilesSmarter (above)
public static FindFilesSmarter ( this pathMasks ) : IEnumerable
pathMasks this The path masks.
Résultat IEnumerable

FindFilesSmarterComplex() public static méthode

always call IsWildcardMatch with a prefix!!!!
public static FindFilesSmarterComplex ( this pathMask, string pathPrefix = null ) : IEnumerable
pathMask this
pathPrefix string
Résultat IEnumerable

FindFilesSmarterComplex() public static méthode

public static FindFilesSmarterComplex ( this pathMasks, string pathPrefix = null ) : IEnumerable
pathMasks this
pathPrefix string
Résultat IEnumerable

FixFilepathSlashes() public static méthode

Replaces Unix style file path separators (/) with Windows style (\).
public static FixFilepathSlashes ( this filepath ) : string
filepath this The filepath.
Résultat string

FormatFilename() public static méthode

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.
Résultat string

GenerateTemplatedFilename() public static méthode

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.
Résultat string

GenerateTemporaryFilename() public static méthode

public static GenerateTemporaryFilename ( this filename ) : string
filename this
Résultat string

GetAllCustomFilePaths() public static méthode

public static GetAllCustomFilePaths ( this filename, string currentDirectory ) : IEnumerable
filename this
currentDirectory string
Résultat IEnumerable

GetCustomFilePath() public static méthode

public static GetCustomFilePath ( this filename, string currentDirectory = null ) : string
filename this
currentDirectory string
Résultat string

GetCustomFilePathOrWalkUp() public static méthode

public static GetCustomFilePathOrWalkUp ( this filename, string currentDirectory = null ) : string
filename this
currentDirectory string
Résultat string

GetDirectoryStack() public static méthode

public static GetDirectoryStack ( this currentDirectory ) : IEnumerable
currentDirectory this
Résultat IEnumerable

GetFileInTempFolder() public static méthode

public static GetFileInTempFolder ( this filename ) : string
filename this
Résultat string

GetFileMD5() public static méthode

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
Résultat string

GetFileSHA1() public static méthode

public static GetFileSHA1 ( this filename ) : string
filename this
Résultat string

GetFullPath() public static méthode

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.
Résultat string

GetMinimalPaths() public static méthode

public static GetMinimalPaths ( this paths ) : IEnumerable
paths this
Résultat IEnumerable

GetMinimalPathsToDictionary() public static méthode

public static GetMinimalPathsToDictionary ( this paths ) : string>.IDictionary
paths this
Résultat string>.IDictionary

GetSubPath() public static méthode

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.
Résultat string

IsFolderEmpty() public static méthode

public static IsFolderEmpty ( string foldername ) : bool?
foldername string
Résultat bool?

IsSimpleSubPath() public static méthode

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
Résultat bool

IsSubPath() public static méthode

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.
Résultat bool

MarkFileTemporary() public static méthode

public static MarkFileTemporary ( this filename ) : string
filename this
Résultat string

NameWithoutExt() public static méthode

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.
Résultat string

NormalizePath() public static méthode

Translates paths starting with \??\ to regular paths.
public static NormalizePath ( this path ) : string
path this The path.
Résultat string

ReadAllBytesFromFile() public static méthode

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.
Résultat void

RelativePathTo() public static méthode

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.
Résultat string

RemoveDeadLnks() public static méthode

public static RemoveDeadLnks ( string folder ) : void
folder string
Résultat void

RemoveEssentiallyEmptyFolders() public static méthode

public static RemoveEssentiallyEmptyFolders ( string folderName ) : bool
folderName string
Résultat bool

RemoveInvalidSymlinks() public static méthode

public static RemoveInvalidSymlinks ( string directory = null, int maxdepth = 3 ) : void
directory string
maxdepth int
Résultat void

RemoveTemporaryFiles() public static méthode

public static RemoveTemporaryFiles ( ) : void
Résultat void

ResetTempFolder() public static méthode

public static ResetTempFolder ( ) : void
Résultat void

TryHardToDelete() public static méthode

public static TryHardToDelete ( this location ) : void
location this
Résultat void

TryHardToMakeFileWriteable() public static méthode

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
Résultat void

TryToHandlePendingRenames() public static méthode

public static TryToHandlePendingRenames ( bool force = false ) : void
force bool
Résultat void

WalkUpPath() public static méthode

public static WalkUpPath ( this filename, string currentDirectory = null ) : string
filename this
currentDirectory string
Résultat string

WalkUpPaths() public static méthode

public static WalkUpPaths ( this filenames, string currentDirectory = null ) : string
filenames this
currentDirectory string
Résultat string

Write() public static méthode

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.
Résultat int

WriteAllBytesToFile() public static méthode

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.
Résultat void

Property Details

OriginalTempFolder public_oe static_oe property

public static string OriginalTempFolder
Résultat string