FileSystemWatcher文件夹中的文件 [英] FileSystemWatcher For Files In Folder

查看:139
本文介绍了FileSystemWatcher文件夹中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我通过使用FileSystemWatcher创建服务来监视文件夹中的文件.当文件夹中有任何新文件到达时,它工作正常,它正在检测并按预期进行其他工作.

如果文件夹中已经存在文件,如何告诉FileSystemWatcher使用这些文件?

如果有人有任何想法,请分享.

解决方案

在观察程序上为Changed事件添加处理程序.如果您已找到Created的附件,我想您可以弄清楚如何附加它.


使用WMI并轮询reqd文件夹:

字符串WMIQuery ="SELECT * FROM __InstanceCreationEvent WITHIN 10"
                                    +"WHERE TargetInstance ISA \" CIM_DirectoryContainsFile \和"
                                    +"TargetInstance.GroupComponent ="
                                    +"\" Win32_Directory.Name ='C:\\ Test \\ MyFolderToMonitor'\"; 



它将检测重命名,创建,修改文件事件.
您也可以参考inspire:
目录监视器服务控件SSIS包执行 [ ^ ]


Hi,

I have create service by using FileSystemWatcher for watching files in the folder. It is working fine when there is any new file arriving in the Folder and it is detecting and doing rest of job as expected.

If there are files already present in Folder, How to Tell FileSystemWatcher to Use these Files?

If anyone has any idea, please share.

解决方案

Add a handler for the Changed event on the watcher. If you''ve figured it out for Created I''m guessing you can figure out how to attach it.


Use WMI and poll the reqd folder :

string WMIQuery = "SELECT * FROM __InstanceCreationEvent WITHIN 10 " 
                                    + " WHERE TargetInstance ISA \"CIM_DirectoryContainsFile\" and "
                                    + " TargetInstance.GroupComponent= "
                                    + " \"Win32_Directory.Name='C:\\Test\\MyFolderToMonitor'\""; 



It will detect rename, create, modify file events..

You may also refer to inspire:
Directory Monitor Service controls SSIS Package Execution[^]


这篇关于FileSystemWatcher文件夹中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆