Show / Hide Table of Contents

Method Path2.GetDirectory


Overload

Gets the parent directory path from path. Examples: @"C:\path\name.ext" -> @"C:\path"; @"C:\path\name\" -> @"C:\path"; @"C:\path" -> @"C:\"; @"name.ext" -> null.

public static string GetDirectory(string path, bool withSeparator = false)
Parameters
path  (string)

Path or filename. Can be null.

withSeparator  (bool)

Don't remove path separator character(s) at the end of the result.

Returns
string

null if there is no parent directory.

Remarks

Calls System.IO.Path.GetDirectoryName, after removing trailing directory separators from path.