FileSystemWatcher does not control the user's local folder or temporary folder of Internet files in Vista (64-bit)

I wrote a test program to monitor my Image folder, which points to the c: \ users [username] \ Pictures folder and temporary Internet files for the same user. This program works fine if I change the folder to another location, for example d: \ persona_pics. Any idea why the events do not occur when I set the specified folder for monitoring?

here is the code.

class Program
    {
        static void Main(string[] args)
        {
            //FileSystemWatcher myJpegFileWatcher = new FileSystemWatcher(@"C:\Users\[username]\AppData\Local\Microsoft\Windows\Temporary Internet Files\low\content.ie5\"); 
            FileSystemWatcher myJpegFileWatcher = new FileSystemWatcher(@"C:\Users\[username]\Pictures\ "); 

            myJpegFileWatcher.Filter = "*.jpg";
            myJpegFileWatcher.Created += new FileSystemEventHandler(myJpegFileWatcher_Created);
            myJpegFileWatcher.Changed += new FileSystemEventHandler(myJpegFileWatcher_Changed);
            myJpegFileWatcher.IncludeSubdirectories = true;
            myJpegFileWatcher.NotifyFilter = NotifyFilters.CreationTime;

            myJpegFileWatcher.EnableRaisingEvents = true;

            Console.Read();

        }

        static void myJpegFileWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            FileInfo duplicateFile = new FileInfo(@e.FullPath);
            bool flag = true;

            while (flag)
            {
                try
                {
                    if (duplicateFile.Length > 20000)
                    {
                        duplicateFile.CopyTo(@"d:\pics\spy\ " + e.Name);
                        flag = false;
                        StreamWriter fs = new StreamWriter(@"d:\pics\log.txt", true);
                        fs.WriteLine("file is being copied:{0}, Size={1}", e.FullPath, duplicateFile.Length);
                        fs.Close();
                    }
                    else
                    {
                        StreamWriter fs = new StreamWriter(@"d:\pics\log.txt", true);
                        fs.WriteLine("file is not being copied:{0}, Size={1}", e.FullPath, duplicateFile.Length);
                        fs.Close();
                    }
                }
                catch (Exception ex)
                {
                    //   
                }
            }

        }

        static void myJpegFileWatcher_Created(object sender, FileSystemEventArgs e)
        {
            FileInfo duplicateFile = new FileInfo(@e.FullPath);
            bool flag = true;

            while (flag)
            {
                try
                {
                    if (duplicateFile.Length > 20000)
                    {
                        duplicateFile.CopyTo(@"d:\pics\spy\ " + e.Name);
                        flag = false;
                        StreamWriter fs = new StreamWriter(@"d:\pics\log.txt", true);
                        fs.WriteLine("file is being copied:{0}, Size={1}", e.FullPath, duplicateFile.Length);
                        fs.Close();
                    }
                }
                catch (Exception ex)
                {
                    //   
                }
            }



        }
    }

Working code.

class program {static void Main (string [] args) {

        FileSystemWatcher myJpegFileWatcher = new FileSystemWatcher(@"C:\Users\[user]\Pictures\"); 

        myJpegFileWatcher.Filter = "*.jpg";

        myJpegFileWatcher.Changed += new FileSystemEventHandler(myJpegFileWatcher_Changed);

        myJpegFileWatcher.IncludeSubdirectories = true;

        myJpegFileWatcher.EnableRaisingEvents = true;

        Console.Read();

    }

    static void myJpegFileWatcher_Changed(object sender, FileSystemEventArgs e)
    {
        FileInfo duplicateFile = new FileInfo(@e.FullPath);
        bool flag = true;

        while (flag)
        {
            try
            {
                if (duplicateFile.Exists)
                {

                    if (duplicateFile.Length > 20000)
                    {
                        try
                        {
                            duplicateFile.CopyTo(@"d:\pics\spy\" + e.Name,true);
                        }
                        catch (Exception ex)
                        {
                            StreamWriter fs = new StreamWriter(@"d:\pics\log.txt", true);
                            fs.WriteLine("Error Inside copying:{0}", ex.Message);
                            fs.Close(); 
                        }
                        finally
                        {
                            flag = false;
                            StreamWriter fs = new StreamWriter(@"d:\pics\log.txt", true);
                            fs.WriteLine("file is being copied:{0}, Size={1}", e.FullPath, duplicateFile.Length);
                            fs.Close();
                        }
                    }
                    else
                    {
                        StreamWriter fs = new StreamWriter(@"d:\pics\log.txt", true);
                        fs.WriteLine("file is not being copied:{0}, Size={1}", e.FullPath, duplicateFile.Length);
                        fs.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                StreamWriter fs = new StreamWriter(@"d:\pics\log.txt", true);
                fs.WriteLine("Error:{0}", ex.Message);
                fs.Close(); 
            }
        }

    }


}
+3
source share
1 answer

FileMon ( SysInternals MSDN). , . , -, " " ..

+2

Source: https://habr.com/ru/post/1716394/


All Articles