C# Class ClrPlus.Platform.FilesystemExtensions

Functions related to handling things regarding files and filesystems.
ファイルを表示 Open project: perpetual-motion/clrplus

Public Properties

Property Type Description
OriginalTempFolder string

Public Methods

Method 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

Method Description
FilesystemExtensions ( ) : System
GetNextPart ( this path ) : string>.Tuple

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

Method Details

CanonicalizePath() public static method

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

CanonicalizePathIfLocalAndExists() public static method

public static CanonicalizePathIfLocalAndExists ( this filename ) : string
filename this
return string

CanonicalizePathWithWildcards() public static method

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

ChangeFileExtensionTo() public static method

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.
return string

CreateWritableWorkingCopy() public static method

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

DirectoryEnumerateFilesSmarter() public static method

public static DirectoryEnumerateFilesSmarter ( this path, SearchOption searchOption ) : IEnumerable
path this
searchOption SearchOption
return IEnumerable

DirectoryEnumerateFilesSmarter() public static method

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.
return IEnumerable

DirectoryExistsAndIsAccessible() public static method

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

EnsureFileIsLocal() public static method

public static EnsureFileIsLocal ( this filename, string localFolder = null ) : string
filename this
localFolder string
return string

FileIsLocalAndExists() public static method

public static FileIsLocalAndExists ( this filename ) : bool
filename this
return bool

FindFilesSmarter() public static method

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.
return IEnumerable

FindFilesSmarter() public static method

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

FindFilesSmarterComplex() public static method

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

FindFilesSmarterComplex() public static method

public static FindFilesSmarterComplex ( this pathMasks, string pathPrefix = null ) : IEnumerable
pathMasks this
pathPrefix string
return IEnumerable

FixFilepathSlashes() public static method

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

FormatFilename() public static method

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.
return string

GenerateTemplatedFilename() public static method

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.
return string

GenerateTemporaryFilename() public static method

public static GenerateTemporaryFilename ( this filename ) : string
filename this
return string

GetAllCustomFilePaths() public static method

public static GetAllCustomFilePaths ( this filename, string currentDirectory ) : IEnumerable
filename this
currentDirectory string
return IEnumerable

GetCustomFilePath() public static method

public static GetCustomFilePath ( this filename, string currentDirectory = null ) : string
filename this
currentDirectory string
return string

GetCustomFilePathOrWalkUp() public static method

public static GetCustomFilePathOrWalkUp ( this filename, string currentDirectory = null ) : string
filename this
currentDirectory string
return string

GetDirectoryStack() public static method

public static GetDirectoryStack ( this currentDirectory ) : IEnumerable
currentDirectory this
return IEnumerable

GetFileInTempFolder() public static method

public static GetFileInTempFolder ( this filename ) : string
filename this
return string

GetFileMD5() public static method

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

GetFileSHA1() public static method

public static GetFileSHA1 ( this filename ) : string
filename this
return string

GetFullPath() public static method

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.
return string

GetMinimalPaths() public static method

public static GetMinimalPaths ( this paths ) : IEnumerable
paths this
return IEnumerable

GetMinimalPathsToDictionary() public static method

public static GetMinimalPathsToDictionary ( this paths ) : string>.IDictionary
paths this
return string>.IDictionary

GetSubPath() public static method

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.
return string

IsFolderEmpty() public static method

public static IsFolderEmpty ( string foldername ) : bool?
foldername string
return bool?

IsSimpleSubPath() public static method

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
return bool

IsSubPath() public static method

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.
return bool

MarkFileTemporary() public static method

public static MarkFileTemporary ( this filename ) : string
filename this
return string

NameWithoutExt() public static method

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.
return string

NormalizePath() public static method

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

ReadAllBytesFromFile() public static method

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.
return void

RelativePathTo() public static method

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.
return string

RemoveDeadLnks() public static method

public static RemoveDeadLnks ( string folder ) : void
folder string
return void

RemoveEssentiallyEmptyFolders() public static method

public static RemoveEssentiallyEmptyFolders ( string folderName ) : bool
folderName string
return bool

RemoveInvalidSymlinks() public static method

public static RemoveInvalidSymlinks ( string directory = null, int maxdepth = 3 ) : void
directory string
maxdepth int
return void

RemoveTemporaryFiles() public static method

public static RemoveTemporaryFiles ( ) : void
return void

ResetTempFolder() public static method

public static ResetTempFolder ( ) : void
return void

TryHardToDelete() public static method

public static TryHardToDelete ( this location ) : void
location this
return void

TryHardToMakeFileWriteable() public static method

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
return void

TryToHandlePendingRenames() public static method

public static TryToHandlePendingRenames ( bool force = false ) : void
force bool
return void

WalkUpPath() public static method

public static WalkUpPath ( this filename, string currentDirectory = null ) : string
filename this
currentDirectory string
return string

WalkUpPaths() public static method

public static WalkUpPaths ( this filenames, string currentDirectory = null ) : string
filenames this
currentDirectory string
return string

Write() public static method

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.
return int

WriteAllBytesToFile() public static method

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.
return void

Property Details

OriginalTempFolder public_oe static_oe property

public static string OriginalTempFolder
return string