Class PathExtensions
Extensions to the System.IO.Path class.
public static class PathExtensions
- Inheritance
-
PathExtensions
- Inherited Members
Methods
GetUnusedFileName(string, Func<string, bool>)
Gets an unused file name, appending " (1)", " (2)", etc., to the file name as necessary.
public static string GetUnusedFileName(string fileName, Func<string, bool> isUsedDelegate)
Parameters
fileNamestringThe preferred file name to use. This should not include a path.
isUsedDelegateFunc<string, bool>A delegate that yields whether a file name is used.
Returns
- string
The unused file name.
Exceptions
- ArgumentNullException
fileNameis null.- ArgumentNullException
isUsedDelegateis null.
SanitizeFileName(string)
Sanitizes a proposed file name so that it does not use any invalid file name characters.
public static string SanitizeFileName(string fileName)
Parameters
fileNamestringThe file name to sanitize.
Returns
- string
The sanitized file name.
Remarks
All invalid characters will be replaced by an underscore ("_"), and leading and trailing whitespace will be trimmed.
Exceptions
- ArgumentNullException
fileNameis null.
SanitizeFileName(string, string)
Sanitizes a proposed file name so that it does not use any invalid file name characters.
public static string SanitizeFileName(string fileName, string defaultFileName)
Parameters
fileNamestringThe file name to sanitize.
defaultFileNamestringA default file name to use if the resulting sanitized name does not contain any original non-whitespace characters left.
Returns
- string
The sanitized file name.
Remarks
All invalid characters will be replaced by an underscore ("_"), and leading and trailing whitespace will be trimmed.
Exceptions
- ArgumentNullException
fileNameis null.- ArgumentNullException
defaultFileNameis null.