我想知道在C#中是否可以找到文件何时添加到文件夹中。我知道你可以在FileInfo中看到创建时间和许多其他信息,但不知道添加时间。
我想知道在C#中是否可以找到文件何时添加到文件夹中。我知道你可以在FileInfo中看到创建时间和许多其他信息,但不知道添加时间。
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
其中OnChanged是一个事件处理程序:
private static void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine($"File: {e.FullPath} {e.ChangeType}");
}
请查看FileSystemWatcher类 - http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
页面底部有一个完整的示例。