简体   繁体   English

Windows(共享)上检查多个文件的最快方法

[英]Fastest way to check multiple files exist on Windows (share)

I've a huge list of file paths to a remote share that I need to check for existence. 我有大量的远程共享文件路径列表,需要检查它们是否存在。 example input: 输入示例:

\\server\\folder1\\file1 \\服务器\\文件夹1 \\文件1
\\server\\folder1\\file2 \\服务器\\文件夹1 \\文件2
\\server\\folder2\\file3 \\服务器\\文件夹2 \\文件3
etc. 等等

We currently simply do File.Exists (which basically uses the FindFirstFile WinAPI) per file but it's pretty slow. 当前,我们仅对每个文件执行File.Exists(基本上使用FindFirstFile WinAPI),但是速度很慢。 Is there any more efficient way of doing it? 有没有更有效的方法呢? is there a way to parallelize is somehow? 有某种方式可以并行化吗?

Using I/O operations is usually slow and expensive. 使用I / O操作通常很慢且昂贵。
I suggest using a different approach all together: 我建议一起使用另一种方法:

Get the list of files once, when the program is initialized, and store it in a database. 程序初始化后,一次获取文件列表,并将其存储在数据库中。

Use a FileSystemWatcher to monitor creation of files within the path (if you have different parent directories or different remote computers you might need to use a FileSystemWatcher for each one), and then update the database on each created, deleted and renamed event for the relevant files. 使用FileSystemWatcher监视路径中文件的创建(如果您具有不同的父目录或不同的远程计算机,则可能需要对每个文件使用FileSystemWatcher),然后针对相关的每个创建,删除和重命名的事件更新数据库。文件。

Then all you have to do to get the files that exists is a simple sql query, that will be lightning fast comparing to iterating on a large list and test for File.Exist 然后,要获取存在的文件,您要做的只是一个简单的sql查询,与在大型列表上进行迭代和测试File.Exist相比,它可以闪电File.Exist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM