Method pathname.getDirectory
Overload
Removes filename part from path.
By default also removes separator ('\\'
or '/'
) if it is not after drive name (eg "C:"
).
public static string getDirectory(string path, bool withSeparator = false)
Parameters
path (string)
Path or filename. Can be |
withSeparator (bool)
Don't remove separator character(s) ( |
Returns
string
Returns |
Remarks
Similar to System.IO.Path.GetDirectoryName. Some differences: skips '\\'
or '/'
at the end (eg from @"C:\A\B\"
gets @"C:\A"
, not @"C:\A\B"
); does not replace '/'
with '\\'
.
Parses raw string. You may want to pathname.normalize it at first.
Supports separators '\\'
and '/'
.
Also supports URL and shell parsing names like @"::{CLSID-1}\0\::{CLSID-2}"
.
Examples:
path | result |
---|---|
@"C:\A\B\file.txt"
|
@"C:\A\B"
|
"file.txt"
|
""
|
@"C:\A\B\"
|
@"C:\A"
|
@"C:\A\/B\/"
|
@"C:\A"
|
@"C:\"
|
null
|
@"\\network\share"
|
null
|
"http:"
|
null
|
@"C:\aa\file.txt:alt.stream"
|
"C:\aa"
|
"http://a.b.c"
|
"http:"
|
"::{A}\::{B}"
|
"::{A}"
|
""
|
""
|
null
|
null
|
Examples when withSeparatortrue
:
path | result |
---|---|
@"C:\A\B"
|
@"C:\A\" (not @"C:\A" ) |
"http://x.y"
|
"http://" (not "http:" ) |