使用Filesystemwatcher自动使用循环打开最新创建的文件

时间:2018-09-22 08:57:29

标签: pdf filesystemwatcher

我正在寻找一种脚本和一种方法,以使Filesystemwatcher自动打开刚刚创建的PDF文件。

有解决方案吗?谢谢。 编辑: 这是我正在运行的代码/脚本。

    using System;
using System.IO;

namespace FileSystemWatcherTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"C:\Users\Administrator\Documents\expo";
            FileSystemWatcher watcher = new FileSystemWatcher();

            watcher.Path = path;//assigning path to be watched
            watcher.EnableRaisingEvents = true;//make sure watcher will raise event in case of change in folder.
            watcher.IncludeSubdirectories = true;//make sure watcher will look into subfolders as well.
            watcher.Filter = "*.*"; //watcher should monitor all types of file.

            watcher.Created += watcher_Created; //register event to be called when a file is created in specified path
            watcher.Changed += watcher_Changed;//register event to be called when a file is updated in specified path
            watcher.Deleted += watcher_Deleted;//register event to be called when a file is deleted in specified path

            while (true) ;//run infinite loop so program doesn't terminate untill we force it.
        }

        static void watcher_Deleted(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("File : " + e.FullPath + " is deleted.");
        }

        static void watcher_Changed(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("File : " + e.FullPath + " is updated.");
        }

        static void watcher_Created(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine("File : " + e.FullPath + " is created.");
        }
    }
}

我只希望它自动打开在目录/文件夹中创建的每个新PDF文件。

谢谢

0 个答案:

没有答案