重命名文件oldName时,.Net FileSystemWatcher为null

时间:2014-04-10 07:54:45

标签: filesystemwatcher .net

我正在尝试跟踪文件系统的变化。因此我使用FileSystemWatcher。遗憾的是,Renamed事件不提供Windows 7和Windows 8上的oldName信息。在Windows XP上,它完美无缺。

这是我的计划:

using System;
using System.IO;

namespace Watcher2
{

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

        Console.WriteLine("Enter Folder Name:");
        string folder = Console.ReadLine();
        Console.WriteLine("Watching folder "+folder);

        FileSystemWatcher watcher = new FileSystemWatcher(folder, "*.*");
        watcher.EnableRaisingEvents = true;
        watcher.IncludeSubdirectories = true;

        watcher.Renamed += watcher_Renamed;

        Console.ReadLine();

    }

    static void watcher_Renamed(object sender, RenamedEventArgs e)
    {
        Console.WriteLine(string.Format("OldName is {0} \nName is {1}\nOldFullPath is {2}\nFullPath is {3}", (e.OldName ?? "NULL"), e.Name, e.OldFullPath, e.FullPath));
    }
}

RenamedEventArgs不提供OldName(e.OldName为NULL)。使用Windows XP是没有选择:)

我在这里错过了什么吗?

1 个答案:

答案 0 :(得分:0)

我现在更新到Windows 8.1,我按预期获得OldName ..