C# FileSystemWatcher 锁定文件夹
我正在尝试使用 C# 和 FileSystemWatcher 监视文件夹。一切正常,除了我可以删除我实际正在观看的文件夹
这一事实我曾经使用 ReadDirectoryChangesW 在 C 中执行此操作,通过创建文件夹的句柄并锁定它,这可以防止从用户删除或重命名该文件夹文件夹(我说的是实际受监视的文件夹,而不是它的内容)
是否有任何方法可以锁定该文件夹,以便人们在监视时不会删除它?
(请注意,我不想更改该文件夹的权限,因为它可能位于 FAT32 分区/USB 驱动器/等上,不支持权限)
I'm trying to monitor a folder using C# and FileSystemWatcher. everything works well, except the fact that i can delete the folder i'm actually watching
I used to do this in C using ReadDirectoryChangesW, by creating a handle to the folder, and locking it, which prevented delete or rename from the user to that folder (i'm talking about the actual monitored folder, not it's contents)
Is there any way to lock that folder so people don't delete it while it's being watched?
(note that I don't want to change permissions to the folder because it might be on a FAT32 partition/usb drive/etc , which doesn't support permissions)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否是一个选项,但您可以在所述文件夹中创建一个(临时)文件,并在“观看”期间保持其打开状态。当然,之后您需要再次清理它。 (您甚至可以给它隐藏属性,这样它就不会显示给“普通”用户)。
这不是最好的解决方案,当您的程序在删除文件之前崩溃时,文件将仍然乱七八糟......
Not sure if that's an option, but you could create a (temporary) file in said folder and keep it open for the duration of the 'watch'. You'll need to clean it up again afterwards off course. (You might even give it the hidden attribute so it doesn't show up to 'normal' users).
Not the nicest solution and the file will remain littering around when your program crashes before removing the file...