用于分析文件写入/修改的 C# 解决方案

发布于 2024-08-10 18:24:04 字数 391 浏览 3 评论 0原文

我有几个项目需要我监视文件,然后在将它们写入磁盘时对其进行编辑。我有一种感觉,我正在寻找的功能在操作上与防病毒工具的操作方式相同。让我提供更多细节: 1)我需要捕获Office应用程序保存的所有文件,然后在将它们写入磁盘时将特定的公司标签添加到每个文档的页眉/页脚。 2)我需要立即知道可编辑文件(几乎任何类型)何时写入磁盘,以便我可以进行一些扫描操作来检查文件内容是否符合某些公司政策。

简而言之,您可以看到我需要在将任何用户文件写入磁盘时对其进行处理。

这是我的问题。我想使用 C# 来完成这项任务,但我不确定它是否有能力满足我的要求。我在网上看到的所有内容都是针对较低级别的 C 编程,由于该项目的时间限制,我特别想避免这种情况。有人知道如何在 C# 中轻松完成此任务吗?它是否可行(即语言太高级、语言太慢等)?

I have several projects that require me to monitor files, and then edit them as they are getting written to disk. I have a feeling that what I am looking for is operationally the same as how anti-virus tools operate. Let me give more details:
1) I need to trap all files saved by Office application, and then add specific company tags to the headers/footers of each document as they are getting written to disk.
2) I need to know immediately when an editable file (of pretty much any type) is written to disk, so that I can undertake some scanning operations to check if files content meets certain company policies.

In short, you can see that I need to process any user files as they are being written to disk.

Here is my problem. I want to use C# for this task, but I am not sure if it has the ability to meet my requirements. Everything I have seen on the net is geared towards lower-level C programming, which I specifically want to avoid due to time constraints for this project. Anyone aware of how to easily do this task in C#? Is it even feasible (ie too high-level a language, too slow a language etc.)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

虫児飞 2024-08-17 18:24:04

性能不会成为问题。我想我会质疑整个过程——这听起来像是一场灾难。您可以在几分钟内使用 FileSystemWatcher 轻松地将 C# 中的某些内容组合在一起,但这会充满问题。反病毒软件在锁定文件和搞砸各种软件方面已经够糟糕的了,而且它甚至不尝试修改文件。您如何知道其他应用程序何时“完成”写入文件?当您锁定文件并且由于无法访问而导致其他内容损坏时,您该怎么办?

Performance won't be the issue. I guess I'd question the entire process- it sounds like a recipe for disaster. You can easily hack something together in C# using a FileSystemWatcher in a matter of minutes, but it will be fraught with issues. AV software is bad enough about locking files and screwing up various software, and it's not even trying to modify the file. How do you know when the other app is "done" writing the file? What do you do when you've got the file locked and something else breaks because it can't get access?

请你别敷衍 2024-08-17 18:24:04

您看过 FileSystemWatcher 吗?

Have you looked at the FileSystemWatcher?

镜花水月 2024-08-17 18:24:04

C# 可以轻松做到这一点。查看 FileSystemWatcher 类 (http ://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx)。

C# can easily do this. Look at the FileSystemWatcher class (http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文