예제 #1
0
        public FileEnum(string path, FileEnumFlags flags)
        {
            this.m_flags = flags;
            this.m_path  = path;

            this.m_openForReadHandle = FileSystemManager.AddToOpenListForRead(this.m_path);
            this.m_findFile          = DriveInfo.GetForPath(this.m_path).Find(this.m_path, "*");
        }
예제 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (this.m_findFile != null)
            {
                this.m_findFile.Close();
                this.m_findFile = null;
            }

            if (this.m_openForReadHandle != null)
            {
                FileSystemManager.RemoveFromOpenList(this.m_openForReadHandle);
                this.m_openForReadHandle = null;
            }

            this.m_disposed = true;
        }
예제 #3
0
        public void Reset()
        {
            if (this.m_disposed)
            {
                throw new ObjectDisposedException();
            }

            if (this.m_findFile != null)
            {
                this.m_findFile.Close();
            }

            if (this.m_openForReadHandle == null)
            {
                this.m_openForReadHandle = FileSystemManager.AddToOpenListForRead(this.m_path);
            }

            this.m_findFile = DriveInfo.GetForPath(this.m_path).Find(this.m_path, "*");
        }
예제 #4
0
        public bool MoveNext()
        {
            if (this.m_disposed)
            {
                throw new ObjectDisposedException();
            }

            var fileinfo = this.m_findFile.GetNext();

            while (fileinfo != null)
            {
                if (this.m_flags != FileEnumFlags.FilesAndDirectories)
                {
                    var targetAttribute = (0 != (this.m_flags & FileEnumFlags.Directories) ? FileAttributes.Directory : 0);

                    if ((fileinfo.Attributes & FileAttributes.Directory) == targetAttribute)
                    {
                        this.m_currentFile = fileinfo;
                        break;
                    }
                }
                else
                {
                    this.m_currentFile = fileinfo;
                    break;
                }

                fileinfo = this.m_findFile.GetNext();
            }

            if (fileinfo == null)
            {
                this.m_findFile.Close();
                this.m_findFile = null;

                FileSystemManager.RemoveFromOpenList(this.m_openForReadHandle);
                this.m_openForReadHandle = null;
            }

            return(fileinfo != null);
        }
예제 #5
0
        private static string[] GetChildren(string path, string searchPattern, bool isDirectory)
        {
            // path and searchPattern validation in Path.GetFullPath() and Path.NormalizePath()

            path = Path.GetFullPath(path);

            if (!Directory.Exists(path))
            {
                throw new IOException("", (int)IOException.IOExceptionErrorCode.DirectoryNotFound);
            }

            Path.NormalizePath(searchPattern, true);

            var fileNames = new ArrayList();

            var root = Path.GetPathRoot(path);

            if (false && string.Equals(root, path))   //TODO check to see it always go here
            /// This is special case. Return all the volumes.
            /// Note this will not work, once we start having \\server\share like paths.

            {
                if (isDirectory)
                {
                    var volumes = DriveInfo.GetDrives();
                    var count   = volumes.Length;
                    for (var i = 0; i < count; i++)
                    {
                        fileNames.Add(volumes[i].RootDirectory.Name);
                    }
                }
            }
            else
            {
                var record = FileSystemManager.AddToOpenListForRead(path);
                IFileSystemEntryFinder ff = null;
                try {
                    ff = DriveInfo.GetForPath(path).Find(path, searchPattern);

                    var targetAttribute = (isDirectory ? FileAttributes.Directory : 0);

                    var fileinfo = ff.GetNext();

                    while (fileinfo != null)
                    {
                        if ((fileinfo.Attributes & FileAttributes.Directory) == targetAttribute)
                        {
                            fileNames.Add(fileinfo.FileName);
                        }

                        fileinfo = ff.GetNext();
                    }
                }
                finally {
                    if (ff != null)
                    {
                        ff.Close();
                    }
                    FileSystemManager.RemoveFromOpenList(record);
                }
            }

            return((string[])fileNames.ToArray(typeof(string)));
        }