Exemplo n.º 1
0
        /// <summary>
        /// Split the current folder in an array of sub-folder names and return it.
        /// </summary>
        /// <returns>Returns a string array of su-folder names (including drive) or null if there are no sub-folders.</returns>
        public static string[] GetDirectories(string folder)
        {
            if (string.IsNullOrEmpty(folder) == true)
            {
                return(null);
            }

            string[] dirs = null;

            try
            {
                dirs = folder.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
            }
            catch
            {
            }

            if (dirs.Length > 0)   // Normalize drive reference from 'C:' to 'C:\'
            {
                if (dirs[0].Contains(":") == true)
                {
                    dirs[0] = PathModel.NormalizeDirectoryPath(dirs[0]);
                }
            }

            return(dirs);
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        /// <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));
            }
        }