gpt4 book ai didi

c# - 文件观察器可以读取放置在观察路径上的文件夹的内容吗?

转载 作者:太空宇宙 更新时间:2023-11-03 14:42:27 25 4
gpt4 key购买 nike

我有一个 Windows 服务可以监视我 PC 上的路径。我的挑战是我遇到了服务问题,不得不停止并修复它。现在,由于服务未运行,监视路径上的子目录中有新文件未处理。我希望能够从路径中剪切文件夹并粘贴它,然后我的服务应该检测到该文件夹​​,这部分工作正常,但它不会继续读取文件夹内的文件。

下面是文件观察器的设置

fileSystemWatcher1.Path = filePath;
fileSystemWatcher1.EnableRaisingEvents = true;
fileSystemWatcher1.IncludeSubdirectories = true;
fileSystemWatcher1.InternalBufferSize = fsWatcherBuffer;
fileSystemWatcher1.Created += new
FileSystemEventHandler(fileSystemWatcher1_Created);
fileSystemWatcher1.Changed += new
FileSystemEventHandler(fileSystemWatcher1_Changed);

最佳答案

我用我的 Windows 10 操作系统做了一些实验,似乎移动一个子文件夹只会引发一个 Created移动目录的事件,但复制粘贴子文件夹会引发 CreatedChanged子文件夹及其所有内容的事件(深度)。

我的观察结果与 documentation 不符虽然:

The operating system and FileSystemWatcher object interpret a cut-and-paste action or a move action as a rename action for a folder and its contents. If you cut and paste a folder with files into a folder being watched, the FileSystemWatcher object reports only the folder as new, but not its contents because they are essentially only renamed.

To be notified that the contents of folders have been moved or copied into a watched folder, provide OnChanged and OnRenamed event handler methods

同样来自 here :

If a directory is created in the sub tree of the directory you are watching, and IncludeSubdirectories is true, that directory will automatically be watched.

关于c# - 文件观察器可以读取放置在观察路径上的文件夹的内容吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56127591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com