Ejemplo n.º 1
0
 public DirectoryInfoExtended(string di, SearchOptionExtended so = SearchOptionExtended.AllDirectories,
                              bool index = false, bool renameFolders = false, bool autoFile = false, bool checkForDuplicates = false, bool cleanupSmallFiles = true)
 {
     DirectoryInfo      = new DirectoryInfo(di);
     SearchOption       = so;
     Index              = index;
     RenameFolders      = renameFolders;
     AutoFile           = autoFile;
     CheckForDuplicates = checkForDuplicates;
     CleanupSmallFiles  = cleanupSmallFiles;
 }
Ejemplo n.º 2
0
        private static IEnumerable <FileInfo> GetFileList(string fileSearchPattern, string rootFolderPath, SearchOptionExtended so, bool includeHidden = false)
        {
            DateTime       writeTimeCutoff = DateTime.UtcNow.AddSeconds(-5);
            string         folderPath      = string.Empty;
            Queue <string> pending         = new Queue <string>();

            pending.Enqueue(rootFolderPath);
            string[] tmp;
            while (pending.Count > 0)
            {
                folderPath = pending.Dequeue();
                if ((folderPath == rootFolderPath && (so == SearchOptionExtended.AllDirectories || so == SearchOptionExtended.TopDirectoryOnly)) || folderPath != rootFolderPath)
                {
                    tmp = Directory.GetFiles(folderPath, fileSearchPattern);
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        var fi = new FileInfo(tmp[i]);

                        if (includeHidden || (!includeHidden && !fi.Attributes.HasFlag(FileAttributes.Hidden)))
                        {
                            if (fi.LastWriteTimeUtc < writeTimeCutoff)
                            {
                                yield return(fi);
                            }
                        }
                    }
                }

                if (so == SearchOptionExtended.AllDirectories || so == SearchOptionExtended.SubDirectories)
                {
                    tmp = Directory.GetDirectories(folderPath);
                    for (int i = 0; i < tmp.Length; i++)
                    {
                        pending.Enqueue(tmp[i]);
                    }
                }
            }
        }