Exemple #1
0
        static internal IEnumerable <FileSystemInfo> EnumerateFileSystemInfos(string full, string searchPattern, SearchOption searchOption)
        {
            string         path_with_pattern = Path.Combine(full, searchPattern);
            IntPtr         handle;
            MonoIOError    error;
            FileAttributes rattr;
            bool           subdirs = searchOption == SearchOption.AllDirectories;

            Path.Validate(full);

            string s = MonoIO.FindFirst(full, path_with_pattern, out rattr, out error, out handle);

            if (s == null)
            {
                yield break;
            }
            if (error != 0)
            {
                throw MonoIO.GetException(Path.GetDirectoryName(path_with_pattern), (MonoIOError)error);
            }

            try {
                if (((rattr & FileAttributes.ReparsePoint) == 0))
                {
                    if ((rattr & FileAttributes.Directory) != 0)
                    {
                        yield return(new DirectoryInfo(s));
                    }
                    else
                    {
                        yield return(new FileInfo(s));
                    }
                }

                while ((s = MonoIO.FindNext(handle, out rattr, out error)) != null)
                {
                    if ((rattr & FileAttributes.ReparsePoint) != 0)
                    {
                        continue;
                    }
                    if ((rattr & FileAttributes.Directory) != 0)
                    {
                        yield return(new DirectoryInfo(s));
                    }
                    else
                    {
                        yield return(new FileInfo(s));
                    }

                    if (((rattr & FileAttributes.Directory) != 0) && subdirs)
                    {
                        foreach (FileSystemInfo child in EnumerateFileSystemInfos(s, searchPattern, searchOption))
                        {
                            yield return(child);
                        }
                    }
                }
            } finally {
                MonoIO.FindClose(handle);
            }
        }
Exemple #2
0
        internal static IEnumerable <string> EnumerateKind(string path, string searchPattern, SearchOption searchOption, FileAttributes kind)
        {
            if (searchPattern.Length == 0)
            {
                yield break;
            }

            bool   stop;
            string path_with_pattern = ValidateDirectoryListing(path, searchPattern, out stop);

            if (stop)
            {
                yield return(path_with_pattern);

                yield break;
            }

            IntPtr         handle;
            MonoIOError    error;
            FileAttributes rattr;
            string         s = MonoIO.FindFirst(path, path_with_pattern, out rattr, out error, out handle);

            try {
                while (s != null)
                {
                    // Convert any file specific flag to FileAttributes.Normal which is used as include files flag
                    if (((rattr & FileAttributes.Directory) == 0) && rattr != 0)
                    {
                        rattr |= FileAttributes.Normal;
                    }

                    if ((rattr & kind) != 0)
                    {
                        yield return(s);
                    }

                    s = MonoIO.FindNext(handle, out rattr, out error);
                }

                if (error != 0)
                {
                    throw MonoIO.GetException(Path.GetDirectoryName(Path.Combine(path, searchPattern)), (MonoIOError)error);
                }
            } finally {
                if (handle != IntPtr.Zero)
                {
                    MonoIO.FindClose(handle);
                }
            }

            if (searchOption == SearchOption.AllDirectories)
            {
                s = MonoIO.FindFirst(path, Path.Combine(path, "*"), out rattr, out error, out handle);

                try {
                    while (s != null)
                    {
                        if ((rattr & FileAttributes.Directory) != 0 && (rattr & FileAttributes.ReparsePoint) == 0)
                        {
                            foreach (string child in EnumerateKind(s, searchPattern, searchOption, kind))
                            {
                                yield return(child);
                            }
                        }
                        s = MonoIO.FindNext(handle, out rattr, out error);
                    }

                    if (error != 0)
                    {
                        throw MonoIO.GetException(path, (MonoIOError)error);
                    }
                } finally {
                    if (handle != IntPtr.Zero)
                    {
                        MonoIO.FindClose(handle);
                    }
                }
            }
        }
Exemple #3
0
        internal static IEnumerable <string> EnumerateKind(string path, string searchPattern, SearchOption searchOption, FileAttributes kind)
        {
            if (searchPattern.Length == 0)
            {
                yield break;
            }

            bool   stop;
            string path_with_pattern = ValidateDirectoryListing(path, searchPattern, out stop);

            if (stop)
            {
                yield return(path_with_pattern);

                yield break;
            }

            IntPtr         handle;
            MonoIOError    error;
            FileAttributes rattr;
            bool           subdirs = searchOption == SearchOption.AllDirectories;

            string s = MonoIO.FindFirst(path, path_with_pattern, out rattr, out error, out handle);

            if (s == null)
            {
                yield break;
            }
            if (error != 0)
            {
                throw MonoIO.GetException(Path.GetDirectoryName(Path.Combine(path, searchPattern)), (MonoIOError)error);
            }

            try
            {
                if (((rattr & FileAttributes.ReparsePoint) == 0) && ((rattr & kind) != 0))
                {
                    yield return(s);
                }

                while ((s = MonoIO.FindNext(handle, out rattr, out error)) != null)
                {
                    if ((rattr & FileAttributes.ReparsePoint) != 0)
                    {
                        continue;
                    }
                    if ((rattr & kind) != 0)
                    {
                        yield return(s);
                    }

                    if (((rattr & FileAttributes.Directory) != 0) && subdirs)
                    {
                        foreach (string child in EnumerateKind(s, searchPattern, searchOption, kind))
                        {
                            yield return(child);
                        }
                    }
                }
            }
            finally
            {
                MonoIO.FindClose(handle);
            }
        }