Class FileNameTricks
This class exposes numerous static methods for manipulating file names. Unlike the objects in the System.File namespace, these methods don't need a real file object. All work on strings that represent file names.
Inheritance
Namespace: WizardWrx
Assembly: WizardWrx.Core.dll
Syntax
public static class FileNameTricks : object
Fields
| Improve this Doc View SourceOS_DRIVE_PATH_DELIMITER
Along with the OS extension delimiter, the sequence of volume separator, followed immediately by a directory separator, is undefined, though one could easily be constructed at run time, although such a construction wouldn't qualify as a constant.
Declaration
public const string OS_DRIVE_PATH_DELIMITER = null
Field Value
Type | Description |
---|---|
System.String |
See Also
| Improve this Doc View SourceOS_EXTENSION_DELIM
Use this to insert an extension delimiter into a file specification, since there seems to be nothing in the System.IO namespace.
Declaration
public const char OS_EXTENSION_DELIM = null
Field Value
Type | Description |
---|---|
System.Char |
Remarks
Strangely, I haven't found a property that returns the extension delimiter.
See Also
| Improve this Doc View SourceOS_WILD_CARD_MULTIPLE
Declaration
public const char OS_WILD_CARD_MULTIPLE = null
Field Value
Type | Description |
---|---|
System.Char |
Remarks
There doesn't appear to be any provision for generating these from anything in the System.IO namespace.
See Also
| Improve this Doc View SourceOS_WILD_CARD_SINGLE
Use this to insert a multiple-character wild card character into a Windows or Unix file name mask.
Declaration
public const char OS_WILD_CARD_SINGLE = null
Field Value
Type | Description |
---|---|
System.Char |
Remarks
There doesn't appear to be any provision for generating these from anything in the System.IO namespace.
See Also
| Improve this Doc View SourceUNC_SERVER_DELIM
The server delimiter string.
Declaration
public const string UNC_SERVER_DELIM = null
Field Value
Type | Description |
---|---|
System.String |
See Also
Methods
| Improve this Doc View SourceEnsureHasTerminalBackslash(String)
Ensure that a path string has NO terminal backslash.
Declaration
public static string EnsureHasTerminalBackslash(string pstrInputPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrInputPath | String to evaluate and change if needed. |
Returns
Type | Description |
---|---|
System.String | Path string that is guaranteed to HAVE a terminal backslash. |
Remarks
This method is deprecated. Use PathAddBackslash.
EnsureNoTerminalBackslash(String)
Ensure that a path string has a terminal backslash.
Declaration
public static string EnsureNoTerminalBackslash(string pstrInputPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrInputPath | String to evaluate and change if needed. |
Returns
Type | Description |
---|---|
System.String | Path string that is guaranteed NOT to have a terminal backslash. |
Remarks
This method is deprecated. Use PathRemoveBackslash.
FileDirName(String, FileNameTricks.TerminaBackslash)
Extract the directory name from a fully qualified file name.
Declaration
public static string FileDirName(string pstrFQFN, FileNameTricks.TerminaBackslash penmTerminaBackslash)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrFQFN | String containing file name to evaluate. |
FileNameTricks.TerminaBackslash | penmTerminaBackslash | A member of the TerminaBackslash, which specifies whether the returned string should have a terminal backslash. |
Returns
Type | Description |
---|---|
System.String | If the function succeeds, the return value is the directory name stripped of its file name. |
FileExtn(String)
Given a string that contains a partially or fully qualified file name, return the extension, without the delimiting dot.
Declaration
public static string FileExtn(string pstrFQFN)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrFQFN | File name string to evaluate. |
Returns
Type | Description |
---|---|
System.String | Extension, less the delimiting dot. |
FQFBasename(String)
Extract the fully qualified base name, that is, all but the extension, from a partially or fully qualified file name.
Declaration
public static string FQFBasename(string pstrFQFN)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrFQFN | Fully or partially qualified file name to evaluate. |
Returns
Type | Description |
---|---|
System.String | All of pstrFQFN except its extension and extension delimiter. |
MakeFQFN(String, String)
Given a file name and a default directory, which may be a null reference or an empty string, return a file name that is guaranteed to be fully qualified.
Declaration
public static string MakeFQFN(string pstrUQFN, string pstrDefaultDir)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrUQFN | String which is assumed to be a relative file name. |
System.String | pstrDefaultDir | String to use as a default path, unless argument pstrUQFN is a fully qualified file name. If this value is null, or an empty string, the current working directory is used. |
Returns
Type | Description |
---|---|
System.String | String that contains a string that is guaranteed to represent a fully qualified file name. |
PathAddBackslash(String)
Ensure that a path string has NO terminal backslash.
Declaration
public static string PathAddBackslash(string pstrInputPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrInputPath | String to evaluate and change if needed. |
Returns
Type | Description |
---|---|
System.String | Path string that is guaranteed to HAVE a terminal backslash. |
PathAddBackslashDeprecated1(String)
Ensure that a path string has NO terminal backslash.
Declaration
public static string PathAddBackslashDeprecated1(string pstrInputPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrInputPath | String to evaluate and change if needed. |
Returns
Type | Description |
---|---|
System.String | Path string that is guaranteed to HAVE a terminal backslash. |
PathAddBackslashDeprecated2(String)
Ensure that a path string has NO terminal backslash.
Declaration
public static string PathAddBackslashDeprecated2(string pstrInputPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrInputPath | String to evaluate and change if needed. |
Returns
Type | Description |
---|---|
System.String | Path string that is guaranteed to HAVE a terminal backslash. |
PathFixup(String, FileNameTricks.TerminaBackslash)
Originally a private method, this method returns a path (directory) name string that is guaranteed to meet the specified requirement, with respect to presence or absence of a terminal backslash.
Declaration
public static string PathFixup(string pstrInputPath, FileNameTricks.TerminaBackslash penmBackslash)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrInputPath | String containing path (directory) name to evaluate. |
FileNameTricks.TerminaBackslash | penmBackslash | A member of the TerminaBackslash, which specifies whether the returned string should have a terminal backslash. |
Returns
Type | Description |
---|---|
System.String | Path (directory) name string that is guaranteed to either have, or omit, a terminal backslash, as specified. |
PathMakeRelative(String, String)
Given a path, such as the fully qualified name of a resource DLL, and a second fully qualified name, such as that of the program directory or current working directory, compute a relative path to the first named path.
Declaration
public static string PathMakeRelative(string pstrFQPath, string pstrDirectoryRelativeTo)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrFQPath | This string is the fully qualified path for which a relative path is required. This string may be the name of a file or a directory, but it must exist in the file system. |
System.String | pstrDirectoryRelativeTo | This string is the fully qualified path relative to which a path to pstrFQPath is required. This string may be the name of a file or a directory, but it must exist in the file system. Whether you supply a file name or that of its directory, the outcome is the same, since this has no effect on the relative path to pstrFQPath. |
Returns
Type | Description |
---|---|
System.String | The returned string is a relative path string, ready for use. |
Remarks
This method uses methods of the System.Uri class to perform its path math, taking advantage of the fact that a path in the file system is a valid URI.
PathRemoveBackslash(String)
Ensure that a path string has a terminal backslash.
Declaration
public static string PathRemoveBackslash(string pstrInputPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrInputPath | String to evaluate and change if needed. |
Returns
Type | Description |
---|---|
System.String | Path string that is guaranteed NOT to have a terminal backslash. |
UQFBasename(String)
Given a string that represents the name of a file, extract only the base name (EXCLUDING the extension).
Declaration
public static string UQFBasename(string pstrFQFN)
Parameters
Type | Name | Description |
---|---|---|
System.String | pstrFQFN | String to evaluate. |
Returns
Type | Description |
---|---|
System.String | Base name extracted from string. This means the unqualified file name, less its directory and its extension. |