Пример #1
0
        public FileSystemInfo[] GetFileSystemInfos(string searchPattern)
        {
            if (Common.IsRunningOnMono())
            {
                var sysInfos          = SysDirectoryInfo.GetFileSystemInfos(searchPattern);
                FileSystemInfo[] fsis = new FileSystemInfo[sysInfos.Length];
                for (var i = 0; i < sysInfos.Length; i++)
                {
                    var e = sysInfos[i].FullName;
                    fsis[i] = Directory.Exists(e)
                        ? (FileSystemInfo) new DirectoryInfo(e)
                        : (FileSystemInfo) new FileInfo(e);
                }
                return(fsis);
            }

            return(Directory.EnumerateFileSystemEntries(FullPath, searchPattern, true, true, System.IO.SearchOption.TopDirectoryOnly)
                   .Select(e => Directory.Exists(e) ? (FileSystemInfo) new DirectoryInfo(e) : (FileSystemInfo) new FileInfo(e)).ToArray());
        }
Пример #2
0
        public FileSystemInfo[] GetFileSystemInfos(string searchPattern, SearchOption searchOption)
        {
            if (Common.IsRunningOnMono())
            {
#if NET_4_0 || NET_4_5
                return(SysDirectoryInfo.GetFileSystemInfos(searchPattern, searchOption).Select(s => s.FullName).Select(e => Directory.Exists(e) ? (FileSystemInfo) new DirectoryInfo(e) : (FileSystemInfo) new FileInfo(e)).ToArray());
#else
                //throw new NotImplementedException("This function is not supported in ");
                var fileInfos   = SysDirectoryInfo.GetFiles(searchPattern);
                var directories = SysDirectoryInfo.GetDirectories(searchPattern);
                List <FileSystemInfo> fileSystemInfos = new List <FileSystemInfo>();
                foreach (System.IO.FileInfo fsi in fileInfos)
                {
                    fileSystemInfos.Add(new FileInfo(fsi.FullName));
                }

                foreach (System.IO.DirectoryInfo fsi in directories)
                {
                    fileSystemInfos.Add(new DirectoryInfo(fsi.FullName));
                }

                if (searchOption != SearchOption.AllDirectories)
                {
                    return(fileSystemInfos.ToArray());
                }

                foreach (var di in SysDirectoryInfo.GetDirectories())
                {
                    fileSystemInfos.AddRange(new DirectoryInfo(di.FullName).GetFileSystemInfos(searchPattern, searchOption));
                }

                return(fileSystemInfos.ToArray());
#endif
            }

            return(Directory.EnumerateFileSystemEntries(FullPath, searchPattern, true, true, searchOption)
                   .Select(e => Directory.Exists(e) ? (FileSystemInfo) new DirectoryInfo(e) : (FileSystemInfo) new FileInfo(e)).ToArray());
        }