Ocronet.Dynamic.Utils.DirPattern.Exist C# (CSharp) Method

Exist() public static method

public static Exist ( string DirName, string EntryPattern ) : bool
DirName string
EntryPattern string
return bool
        public static bool Exist(string DirName, string EntryPattern)
        {
            bool result = false;
            Regex regex = new Regex(EntryPattern + "$");
            string[] entries = { };
            try
            {
                entries = Directory.GetFileSystemEntries(DirName);
            }
            catch (DirectoryNotFoundException) { }
            foreach (string entry in entries)
            {
                string fileName = Path.GetFileName(entry);
                Match match = regex.Match(entry);
                if (match.Success && fileName == match.Value)
                {
                    result = true;
                    break;
                }
            }
            return result;
        }

Same methods

DirPattern::Exist ( string DirName, string SubDirPattern, string EntryPattern ) : bool

Usage Example

Beispiel #1
0
 public override void SetPrefix(string prefix)
 {
     if (DirPattern.Exist(prefix, @"[0-9][0-9][0-9][0-9]", @"([0-9][0-9][0-9][0-9])\.png"))
     {
         Global.Debugf("info", "selecting OldBookStore");
         p = new OldBookStore();
     }
     else
     {
         Global.Debugf("info", "selecting (new) BookStore");
         p = new BookStore();
     }
     p.SetPrefix(prefix);
 }