知道Windows 8上文件何时更改 [英] Know when a file changes on windows 8
问题描述
我知道FileSystemWatcher类在Windows 8上不起作用.
I know that the class FileSystemWatcher does not work on windows 8. Why are FileSystemWatcher Attribute changes detected on Windows 7 but not Windows 8?
无论如何,我都需要知道目录中文件的更改时间.例如,我在计算机上安装了保管箱,当我更新文件时,它开始同步. Dropbox如何知道Windows 8中文件的更改时间?
Anyways I need to know when a file is changed within a directory. For example I have dropbox installed on my computer and the moment I update a file it starts synchronizing. How does dropbox knows when a file has changed in windows 8?
我已经在c ++中尝试过此解决方案 http://msdn.microsoft.com/zh-cn/library/aa365261 ,我遇到的问题与FileSystemWatcher相同.问题似乎出在Windows 8而不是类FileSystemWatcher. 我可以采取什么解决方案?
I already tried this solution in c++ http://msdn.microsoft.com/en-us/library/aa365261 and I have the same problem as FileSystemWatcher. The problem seems to be from windows 8 instead of the class FileSystemWatcher. What work around solution can I take?
推荐答案
这是我在等待新dll编译然后将其复制到目标文件夹之前使用的一些代码,它似乎可以正常工作.
Here's some code I've used before to wait for a new dll to be compiled and then copy it to some target folder, and it seems to work okay.
static void StartWatching(string path)
{
var watcher = new FileSystemWatcher();
watcher.Path = path;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName |
NotifyFilters.DirectoryName;
watcher.Changed += watcher_Created;
watcher.Created += watcher_Created;
watcher.EnableRaisingEvents = true;
var copier = new Thread(ConsumeOutOfTheFilesToCopyQueue);
copier.Start();
}
static void watcher_Created(object sender, FileSystemEventArgs e)
{
if (e.Name.Contains("whatever.dll"))
if (!_filesToCopy.Contains(e.FullPath))
lock (_syncRoot)
if (!_filesToCopy.Contains(e.FullPath))
_filesToCopy.Enqueue(e.FullPath);
}
这篇关于知道Windows 8上文件何时更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!