Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. FileSystemWatcher filter problem and how it works

FileSystemWatcher filter problem and how it works

Scheduled Pinned Locked Moved C#
questionhelptutorial
5 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xmen Real
    wrote on last edited by
    #1

    FSW dont raise event when i set its filter to custom extension, like if i set it to "*.abcd" then no event will raise but if i set it to other known extensions like "*.txt" or something else it works, any idea how to solve ? my second question is that how it works, is it works like timer mean it keep refresh after some inbuilt specified time or any window function send info to it when a file created and it raises event ? thanks

    TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

    K 1 Reply Last reply
    0
    • X Xmen Real

      FSW dont raise event when i set its filter to custom extension, like if i set it to "*.abcd" then no event will raise but if i set it to other known extensions like "*.txt" or something else it works, any idea how to solve ? my second question is that how it works, is it works like timer mean it keep refresh after some inbuilt specified time or any window function send info to it when a file created and it raises event ? thanks

      TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      K Offline
      K Offline
      KaptinKrunch
      wrote on last edited by
      #2

      FSW monitors a directory for file creation, modification, deletion and renaming. The custom expression is to monitor only those file types that match that expression. This example monitors only the directory where dir == the directory to monitor and only raise an event on file types of txt.

      fileWatcher = new FileSystemWatcher(dir, "*.txt");
      fileWatcher.EnableRaisingEvents = false;
      fileWatcher.IncludeSubdirectories = false;
      fileWatcher.NotifyFilter = NotifyFilters.FileName;
      fileWatcher.Created += new FileSystemEventHandler(fileWatcher_Created);

      Set fileWatcher.EnableRaisingEvents = true to enable the monitoring. To stop monitoring set the value to false. http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^]

      Just because we can; does not mean we should.

      X 1 Reply Last reply
      0
      • K KaptinKrunch

        FSW monitors a directory for file creation, modification, deletion and renaming. The custom expression is to monitor only those file types that match that expression. This example monitors only the directory where dir == the directory to monitor and only raise an event on file types of txt.

        fileWatcher = new FileSystemWatcher(dir, "*.txt");
        fileWatcher.EnableRaisingEvents = false;
        fileWatcher.IncludeSubdirectories = false;
        fileWatcher.NotifyFilter = NotifyFilters.FileName;
        fileWatcher.Created += new FileSystemEventHandler(fileWatcher_Created);

        Set fileWatcher.EnableRaisingEvents = true to enable the monitoring. To stop monitoring set the value to false. http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^]

        Just because we can; does not mean we should.

        X Offline
        X Offline
        Xmen Real
        wrote on last edited by
        #3

        i know that, i think you didnt read my problem properly :) i said it dont raise any event when i set custom filter, for example if i write FSW.Filter = "*.abcd"; // wont work, if i create any file with extension abcd but if i write FSW.Filter = **.txt"; // will work, if i create any file with extension txt EDITED : SOLVED

        TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

        K 1 Reply Last reply
        0
        • X Xmen Real

          i know that, i think you didnt read my problem properly :) i said it dont raise any event when i set custom filter, for example if i write FSW.Filter = "*.abcd"; // wont work, if i create any file with extension abcd but if i write FSW.Filter = **.txt"; // will work, if i create any file with extension txt EDITED : SOLVED

          TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

          K Offline
          K Offline
          KaptinKrunch
          wrote on last edited by
          #4

          Not sure where your having problems. I did this test and had no problems getting the notifications. Sorry

              private void Form1\_Load(object sender, EventArgs e)
              {
                  fileSystemWatcher1 = new System.IO.FileSystemWatcher(@"C:\\");
                  fileSystemWatcher1.IncludeSubdirectories = false;
                  fileSystemWatcher1.NotifyFilter = NotifyFilters.FileName;
                  fileSystemWatcher1.Filter = "\*.abcd";
                  fileSystemWatcher1.Created += new System.IO.FileSystemEventHandler(fileSystemWatcher1\_Created);
                  fileSystemWatcher1.Changed += new System.IO.FileSystemEventHandler(fileSystemWatcher1\_Changed);
                  fileSystemWatcher1.Renamed += new RenamedEventHandler(fileSystemWatcher1\_Renamed);
                  fileSystemWatcher1.Deleted += new FileSystemEventHandler(fileSystemWatcher1\_Deleted);
                  fileSystemWatcher1.EnableRaisingEvents = true;
          
                  File.Delete(@"C:\\test.abcd");
                  StreamWriter sw = new StreamWriter(@"C:\\test.abcd",true);
                  sw.WriteLine("test");
                  sw.Close();
                  sw.Dispose();
              }
          
              void fileSystemWatcher1\_Deleted(object sender, FileSystemEventArgs e)
              {
                  MessageBox.Show("File Deleted " + e.FullPath.ToString());
              }
          
              void fileSystemWatcher1\_Renamed(object sender, RenamedEventArgs e)
              {
                  MessageBox.Show("File Renamed " + e.FullPath.ToString());
              }
          
              void fileSystemWatcher1\_Changed(object sender, System.IO.FileSystemEventArgs e)
              {
                  MessageBox.Show("File Changed " + e.FullPath.ToString());
              }
          
              void fileSystemWatcher1\_Created(object sender, System.IO.FileSystemEventArgs e)
              {
                  MessageBox.Show("File Created " + e.FullPath.ToString());
              }
          

          Just because we can; does not mean we should.

          X 1 Reply Last reply
          0
          • K KaptinKrunch

            Not sure where your having problems. I did this test and had no problems getting the notifications. Sorry

                private void Form1\_Load(object sender, EventArgs e)
                {
                    fileSystemWatcher1 = new System.IO.FileSystemWatcher(@"C:\\");
                    fileSystemWatcher1.IncludeSubdirectories = false;
                    fileSystemWatcher1.NotifyFilter = NotifyFilters.FileName;
                    fileSystemWatcher1.Filter = "\*.abcd";
                    fileSystemWatcher1.Created += new System.IO.FileSystemEventHandler(fileSystemWatcher1\_Created);
                    fileSystemWatcher1.Changed += new System.IO.FileSystemEventHandler(fileSystemWatcher1\_Changed);
                    fileSystemWatcher1.Renamed += new RenamedEventHandler(fileSystemWatcher1\_Renamed);
                    fileSystemWatcher1.Deleted += new FileSystemEventHandler(fileSystemWatcher1\_Deleted);
                    fileSystemWatcher1.EnableRaisingEvents = true;
            
                    File.Delete(@"C:\\test.abcd");
                    StreamWriter sw = new StreamWriter(@"C:\\test.abcd",true);
                    sw.WriteLine("test");
                    sw.Close();
                    sw.Dispose();
                }
            
                void fileSystemWatcher1\_Deleted(object sender, FileSystemEventArgs e)
                {
                    MessageBox.Show("File Deleted " + e.FullPath.ToString());
                }
            
                void fileSystemWatcher1\_Renamed(object sender, RenamedEventArgs e)
                {
                    MessageBox.Show("File Renamed " + e.FullPath.ToString());
                }
            
                void fileSystemWatcher1\_Changed(object sender, System.IO.FileSystemEventArgs e)
                {
                    MessageBox.Show("File Changed " + e.FullPath.ToString());
                }
            
                void fileSystemWatcher1\_Created(object sender, System.IO.FileSystemEventArgs e)
                {
                    MessageBox.Show("File Created " + e.FullPath.ToString());
                }
            

            Just because we can; does not mean we should.

            X Offline
            X Offline
            Xmen Real
            wrote on last edited by
            #5

            thanks for reply but as i said in previous post that problem solved because i had an error in that extension :) :)

            TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups