/// <summary> /// Returns a normalized directory reference from a path reference /// or the parent directory path if the <paramref name="dirPath"/> /// reference points to a file. /// </summary> /// <param name="dirPath"></param> /// <returns></returns> public static string ExtractDirectoryRoot(string dirPath) { bool bExists = false; if (PathModel.CheckValidString(dirPath) == false) { return(null); } try { bExists = System.IO.Directory.Exists(dirPath); } catch { } if (bExists == true) { return(PathModel.NormalizeDirectoryPath(dirPath)); } else { bExists = false; string path = string.Empty; try { // check if this is a file reference and attempt to get its path path = System.IO.Path.GetDirectoryName(dirPath); bExists = System.IO.Directory.Exists(path); } catch { } if (string.IsNullOrEmpty(path) == true) { return(null); } if (path.Length <= 3) { return(null); } if (bExists == true) { return(PathModel.NormalizeDirectoryPath(path)); } return(null); } }
/// <summary> /// Class constructor /// </summary> public PathModel(string path, FSItemType itemType) : this() { mItemType = itemType; switch (itemType) { case FSItemType.Folder: case FSItemType.LogicalDrive: mPath = PathModel.NormalizeDirectoryPath(path); break; case FSItemType.File: mPath = PathModel.NormalizePath(path); break; case FSItemType.DummyEntry: break; case FSItemType.Unknown: default: throw new NotImplementedException(string.Format("Enumeration member: '{0}' not supported.", itemType)); } }