Maybe I need a regex?

I am making a simple console application for a home project. Basically, it controls the folder for any added files.

FileSystemWatcher fsw = new FileSystemWatcher(@"c:\temp");
fsw.Created += new FileSystemEventHandler(fsw_Created);

bool monitor = true;

while (monitor)
{
    fsw.WaitForChanged(WatcherChangeTypes.Created, 1000);
    if(Console.KeyAvailable)
    {
        monitor = false;
    }
}

Show("User has quit the process...", ConsoleColor.Yellow);

When new files appear, WaitForChanges is called and I can get started.

What I need to do is check the file name for the templates. In real life, I put video files in this folder. Based on the file name, I will have rules that move files to specific directories. So, for now, I will have a list of KeyValue pairs ... containing RegEx (I think?) And a folder. So, if the file name matches the regular expression, it moves it to the appropriate folder.

Example file name:

CSI- NY.S07E01.The 34th Floor.avi

, Regex , CSI "AND" (NY "OR" NewYork "" New York "). , \Series\CSI\NY\.

, :

CSI- Crime Scene Investigation.S11E16.Turn On, Tune In, Drop Dead

, NOT. , , CSI, NOT ( "-" "-" "-" )

- RegEx? , , ?

+3
4

, . , // - , , , .

CSI AND NY . , , CSI , "CSI". , . , NY, New York NewYork, "((NY)|(New York)|(NewYork))" OR, . , , ( , ) . , show "(CSI).*((NY)|(New York)|(NewYork))" " ", .

+2

Func<string,bool>

Dictionary<Func<string,bool>,string> dic = new Dictionary<Func<string, bool>, string>();
Func<string, bool> f1 = x => x.Contains("CSI") && ((x.Contains("NY") || x.Contains("New York"));

dic.Add(f1,"C://CSI/");

foreach (var pair in dic)
{
    if(pair.Key.Invoke("CSI- NY.S07E01.The 34th Floor.avi"))
    {
        // copy
        return;
    }
}
+3

, . , "- ", . : , , . "CSI" "NY", - , . , . , , , , , .

+2

, , :

  • Func #,

.

. @Anton S. Kraievoy: , - . : !text.Contains(word)

, , ...

, , , :

  • , ( ..). :
    • "CSI" & ("NY" || "Las Vegas")
  • , .

DSL.

, #?

, :

  • , , .

, .

:

  • ( 100%, , ), , #.
    : "A" & "B" string.Contains("A") && string.Contains("B") - .
  • , ANTLR.
+2

All Articles