From 8c89ff6defcc3438a4080495df314814ca0be859 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 27 Oct 2021 17:18:21 +0100 Subject: [PATCH] Changed: smart-directory and refactoring --- MainForm.cs | 4 ++-- RandomFileRunner.csproj | 7 ++++--- .../IO/SmartDirectory.cs | 11 +++++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) rename IO/SmartFileSystem.cs => RyzStudio/IO/SmartDirectory.cs (96%) diff --git a/MainForm.cs b/MainForm.cs index 094d3e9..c0896b1 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -124,7 +124,7 @@ namespace RandomFileRunner if (File.Exists(item)) { - if (SmartFileSystem.IsFileAccessible(item)) + if (SmartDirectory.IsFileAccessible(item)) { foundFiles.Add(item); ThreadControl.SetText(label2, foundFiles.Count.ToString()); @@ -135,7 +135,7 @@ namespace RandomFileRunner if (Directory.Exists(item)) { - SmartFileSystem.GetFiles(item, textBox1.Text, SearchDirecory_OnFound); + SmartDirectory.GetFiles(item, textBox1.Text, SearchDirecory_OnFound); ThreadControl.SetText(label2, foundFiles.Count.ToString()); diff --git a/RandomFileRunner.csproj b/RandomFileRunner.csproj index aef1233..38b0b0c 100644 --- a/RandomFileRunner.csproj +++ b/RandomFileRunner.csproj @@ -21,20 +21,21 @@ - - - + + + + diff --git a/IO/SmartFileSystem.cs b/RyzStudio/IO/SmartDirectory.cs similarity index 96% rename from IO/SmartFileSystem.cs rename to RyzStudio/IO/SmartDirectory.cs index 6b75186..2921c02 100644 --- a/IO/SmartFileSystem.cs +++ b/RyzStudio/IO/SmartDirectory.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace RandomFileRunner.IO { - public class SmartFileSystem + public class SmartDirectory { public static List GetFiles(string path, string pattern) @@ -16,6 +16,8 @@ namespace RandomFileRunner.IO List fileList = new List(); List directoryList = new List(); + if (string.IsNullOrWhiteSpace(pattern)) pattern = "*"; + directoryList.Add(path); while (true) @@ -51,8 +53,13 @@ namespace RandomFileRunner.IO directoryList.Add(item); } - foreach (string item in Directory.EnumerateFiles(directory, pattern, SearchOption.TopDirectoryOnly)) + foreach (string item in Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly)) { + if (!MatchFileSearchPattern(pattern, Path.GetFileName(item))) + { + continue; + } + if (!IsFileAccessible(item)) { continue;