使用 FileSystemWatcher 监视目录
您好,我正在使用 FileSystemWatcher 监视目录。
当在该目录中创建文件时 - 我的观察者抓取并将其传输到网络驱动器。 我的问题是,当打开 Microsoft-office 文件时,会在监视目录中创建一个临时文件。我找不到忽略这些文件的方法,也找不到何时应将这些文件移动到网络驱动器。
Hello I'm watching a directory using FileSystemWatcher.
When a file is created into that directory - my watcher grabs and transfers it to the network drive.
My problem is that when a Microsoft-office file is opened, a temporary file is created in the watched directory. I can't find a way to ignore these files and also could not find when I should move these file to the network drive.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
临时文件具有引用它的文件属性。
如果 FileInfo.Attributes
检查此 文件属性
Temporary files have file attribute that cite it.
You can check for this attribute if the FileInfo.Attributes
check this FileAttributes
如果我没记错的话,这些临时文件是隐藏文件。如果这不起作用,您可能会考虑允许程序忽略具有特殊名称的文件(这些临时文件以波浪号〜开头)。使用正则表达式,您可以设置更多这样的“忽略掩码”。
If I'm not mistaking, those temporary files are hidden files. If that doesn't work, you might consider allowing files with special names (those temporary files start with a tilde ~) to be ignored by your program. Using Regular Expressions you could set more "ignore masks" like that.