Esempio n. 1
0
        /// <summary>
        /// Returns a set of files that are contained within the desired folder path
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        public bool HasFolderChildren(string folder, bool caseSensitive)
        {
            bool bFolder = false;

            if (folder.Length == 0)
            {
                folder = "<Root>";
            }

            if (mBank.Contains(folder))
            {
                DirectorySetInfo currentFolder = mBank[folder] as DirectorySetInfo;


                IDictionaryEnumerator file = currentFolder.Contents.GetEnumerator();

                // Now itterate through those children
                while (file.MoveNext())
                {
                    DirectorySetInfo fileInfo = file.Value as DirectorySetInfo;
                    if (fileInfo.Type == DirectorySetInfo.TYPE.Folder || fileInfo.Type == DirectorySetInfo.TYPE.FolderName)
                    {
                        bFolder = true;
                        break;
                    }
                }
            }

            return(bFolder);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a set of files that are contained within the desired folder path
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        public HybridDictionary GetFiles(string folder)
        {
            if (folder.Length == 0)
            {
                folder = "<Root>";
            }

            if (mBank.Contains(folder))
            {
                DirectorySetInfo currentFolder = mBank[folder] as DirectorySetInfo;
                return(currentFolder.Contents);
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Add a folder or file to the tree
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="file"></param>
        private void AddFilename(string directory, string file, bool isFolder)
        {
            // Blank directories are not allowed in the b-tree so I convert to a <root> token
            if (directory.Length == 0)
            {
                directory = "<Root>";
            }

            DirectorySetInfo currentFolder = null;

            // Does this folder already exist?
            if (mBank.Contains(directory) == false)
            {
                // If we are not the root, we should add it to our parent folder
                if (directory != "<Root>")
                {
                    // Add this folder to its parent
                    string parentDir = GetParentDirectory(directory);
                    AddFilename(parentDir, directory, true);
                }

                // Make a new folder branch
                currentFolder = new DirectorySetInfo(directory, DirectorySetInfo.TYPE.Folder);

                // Add it to our main tree
                mBank.Add(directory, currentFolder);
            }
            else
            {
                // Ah, it exists.  Get a handle to it
                currentFolder = mBank[directory] as DirectorySetInfo;
            }

            // Now we add the file or folder to this current folder
            if (isFolder)
            {
                // We only want to add the folder name proper to this current folder, so strip off every thing but the name
                string subFolder = RemoveParentDirectory(file, directory);
                subFolder = subFolder.TrimStart("\\".ToCharArray());
                currentFolder.AddFolder(subFolder);
            }
            else
            {
                currentFolder.AddFile(Path.GetFileName(file));
            }
        }