找出何时将文件添加到文件夹

Mik*_*kel 10 c# directory file

我想知道是否有可能找出何时将文件添加到C#中的文件夹中.我知道你可以在FileInfo中看到创建的时间和许多其他的东西,但是当它被添加时就可以了.

PVi*_*itt 15

您可以使用System.IO.FileSystemWatcher.它提供了完成您想要做的事情的方法:

FileSystemWatcher watcher = new FileSystemWatcher()
{
    Path = stringWithYourPath,
    Filter = "*.txt"
};
// Add event handlers for all events you want to handle
watcher.Created += new FileSystemEventHandler(OnChanged);
// Activate the watcher
watcher.EnableRaisingEvents = true
Run Code Online (Sandbox Code Playgroud)


Llo*_*oyd 8

查看FileSystemWatcher类 - http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

您将在页面底部找到完整的示例.