private void SearchFilesQueue() { if (PathTextBox.Text.Length > 0 && DateTextBox.Text.Length > 0) { StatusLabel.Text = "Zähle Dateien... Das kann sehr lange dauern..."; StatusLabel.Update(); //get the list of files. This can be run for a long! time.. IEnumerable <string> files = EnumerateFiles(PathTextBox.Text); DateTime fileCreationDate; DateTime searchDate = DateTime.Parse(DateTextBox.Text); int counter = 0; int lastTick = 0; int amount = files.Count <string>(); foreach (var file in files) { counter++; //Console.WriteLine(file); //fileCreationDate = File.GetCreationTime(file); FileSystemInfo fsi = new FileInfo(file); fileCreationDate = fsi.CreationTime; // System.IO.DirectoryInfo.EnumerateFiles(file) ;//.Crea; if (fileCreationDate < searchDate) { if (FilesListBox.Items.Count == lastTick) { //Console.WriteLine(lastTick+" Dateien gefunden..."); StatusLabel.Text = counter + " / " + amount + " Dateien durchsucht und " + lastTick + " alte Dateien gefunden"; StatusLabel.Update(); FilesListBox.Update(); lastTick += 100; } FilesListBox.Items.Add(file); } } StatusLabel.Text = FilesListBox.Items.Count + " Dateien gefunden"; StatusLabel.Update(); MessageBox.Show("Es gibt " + FilesListBox.Items.Count + " Dateien, die den Suchparametern entsprechen!"); StatusLabel1.Text = ""; StatusLabel1.Update(); } }
internal IEnumerable <string> EnumeratePaths(string root) { if (root == null) { throw new ArgumentNullException("root"); } if (!Directory.Exists(root)) { throw new ArgumentException("Invalid root path", "root"); } if (root.Length > 3) { root = Path.GetDirectoryName(root + "\\"); } Queue <string> queue = new Queue <string>(); queue.Enqueue(root); while (queue.Count > 0) { string curr = queue.Dequeue(); bool failed = false; StatusLabel1.Text = "bearbeite Verzeichnis: " + curr; StatusLabel1.Update(); try { foreach (var path in Directory.GetDirectories(curr)) { queue.Enqueue(path); } } catch { failed = true; } if (!failed) { yield return(curr); } } }