示例#1
0
 public void Dispose()
 {
     if (this._currentEnumerator != null)
     {
         this._currentEnumerator.Dispose();
         this._currentEnumerator = null;
     }
     while (this._enumerators.Count > 0)
     {
         FolderEnumerator e = this._enumerators.Pop();
         e.Dispose();
     }
 }
示例#2
0
        private bool MoveNext_Recursive_FilesAndFolders()
        {
            bool result = false;

            result = this._currentEnumerator.MoveNext();
            //If success and we have a file, just return it
            if (result && this.Current is FileInfo)
            {
                return(result);
            }
            //If success and we have a folder - descend into it
            if (result && this.Current is DirectoryInfo)
            {
                //Push the enumerator on the stack
                this._enumerators.Push(this._currentEnumerator);
                //Create a new enumerator and set it as the current one.
                this._currentEnumerator = new FolderEnumerator(this.Current.FullName);
                //Call back into this method
                return(this.MoveNext_Recursive_FilesAndFolders());
            }
            //If not success, then we're at the end of the current folder
            //If there are no more enumerators then we're done.
            if (!result && this._enumerators.Count == 0)
            {
                this._currentEnumerator.Dispose(); return(result);
            }
            //Not success, pop the enumerator off the stack if there is one
            if (!result && this._enumerators.Count > 0)
            {
                //Clean up the current before letting go of it.
                this._currentEnumerator.Dispose();
                //Get one off the stack
                this._currentEnumerator = this._enumerators.Pop();
                //This one should have a folder on it waiting for us, return it.
                if (this.Current is DirectoryInfo)
                {
                    return(true);
                }
            }
            return(result);
        }
示例#3
0
        private bool MoveNext_Recursive_FilesOnly()
        {
            bool result = false;

            result = this._currentEnumerator.MoveNext();
            //If success and we have a file, just return it
            if (result && this.Current is FileInfo)
            {
                return(result);
            }
            //If success and we have a folder - descend into it
            if (result && this.Current is DirectoryInfo)
            {
                //Push the enumerator on the stack
                this._enumerators.Push(this._currentEnumerator);
                //Create a new enumerator and set it as the current one.
                this._currentEnumerator = new FolderEnumerator(this.Current.FullName);
                //Call back into this method
                return(this.MoveNext_Recursive_FilesOnly());
            }
            //If not success, then we're at the end of the current folder
            //If there are no more enumerators then we're done.
            if (!result && this._enumerators.Count == 0)
            {
                this._currentEnumerator.Dispose(); return(result);
            }
            //If there are enumerators then we need to pop one off the stack
            //Keep going till we have something other than a directory or no more file system entries
            while (!result && this._enumerators.Count > 0)
            {
                //Clean up the current before letting go of it.
                this._currentEnumerator.Dispose();
                //Get one off the stack
                this._currentEnumerator = this._enumerators.Pop();
                //Call back into this method
                return(this.MoveNext_Recursive_FilesOnly());
            }
            return(result);
        }
示例#4
0
        private bool MoveNext_Recursive_FoldersOnly()
        {
            bool result = false;

            //Run till we get another folder.
            while ((result = this._currentEnumerator.MoveNext()) && this.Current is FileInfo)
            {
            }
            //If success, we're guaranteed to have a folder, descend into the folder without returning it at this point.
            if (result)
            {
                //Push it on to the stack
                this._enumerators.Push(this._currentEnumerator);
                //Set the curretn enumerator o this folder
                this._currentEnumerator = new FolderEnumerator(this.Current.FullName);
                //Call back into this method
                return(this.MoveNext_Recursive_FoldersOnly());
            }
            //Not success and there are none left on the stack, then just return false.  we're done
            if (!result && this._enumerators.Count == 0)
            {
                this._currentEnumerator.Dispose(); return(false);
            }
            //Not success, pop the enumerator off the stack if there is one
            if (!result && this._enumerators.Count > 0)
            {
                //Clean up the current before letting go of it.
                this._currentEnumerator.Dispose();
                //Get one off the stack
                this._currentEnumerator = this._enumerators.Pop();
                //This one should have a folder on it waiting for us, return it.
                if (this.Current is DirectoryInfo)
                {
                    return(true);
                }
            }
            return(result);
        }
示例#5
0
 internal FSEnumerator(string rootFolder, EnumertorType type = EnumertorType.FilesOnly)
 {
     this._type = type;
     this._currentEnumerator = new FolderEnumerator(rootFolder);
 }