文章标题

来源:互联网 发布:节流装置计算软件 编辑:程序博客网 时间:2024/06/13 08:47
     //C#中监视文件或文件夹的变换        //注意引用命名空间using System.IO;

using System;
using System.Collections.Generic; using System.Linq; using
System.Text; using System.IO;
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @”D:\UIMRIS\BRANCHES\uMR_MAIN\UIH\log”;
//watcher.Filter = “”;
watcher.InternalBufferSize = 1024 * 100;//100 KB
watcher.IncludeSubdirectories = true;
watcher.Changed += new FileSystemEventHandler(FileChangedHandler);
watcher.Created += new FileSystemEventHandler(FileCreatedHandler);

        ////watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite;        watcher.EnableRaisingEvents = true; // Begin watching.        //string dt1 = DateTime.Now.ToString("yyyy-MM-dd");        while (true)        {            watcher.WaitForChanged(WatcherChangeTypes.All);        }    }    static void FileChangedHandler(object sender, FileSystemEventArgs e)    {        Console.WriteLine("The file watched is changed!" + e.FullPath + e.ChangeType);    }    static void FileCreatedHandler(object sender, FileSystemEventArgs e)    {        Console.WriteLine("A file is created!" + e.FullPath + e.ChangeType);    }

/****************C#中获取文件信息**************************/

    FileInfo fi = new FileInfo("D:/UIMRIS/BRANCHES/uMR_MAIN/UIH/log/2016-05-23/0.uihlog");            Console.WriteLine(fi.LastWriteTime);             Thread.Sleep(2000);
0 0
原创粉丝点击