从包含大量文件的目录中检索文件 [英] Retrieving files from directory that contains large amount of files

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

问题描述

我的目录包含近 14,000,000 个 *.wav 格式的音频样本.

I have directory that contains nearly 14,000,000 audio samples in *.wav format.

所有普通存储,没有子目录.

All plain storage, no subdirectories.

我想遍历文件,但是当我在该文件夹上使用 DirectoryInfo.GetFiles() 时,整个应用程序会冻结几分钟!

I want to loop through the files, but when I use DirectoryInfo.GetFiles() on that folder the whole application freezes for minutes!

这可以用另一种方式完成吗?也许读取 1000 个,处理它们,然后取下 1000 个等等?

Can this be done another way? Perhaps read 1000, process them, then take next 1000 and so on?

推荐答案

您是否尝试过 EnumerateFiles DirectoryInfo 类的方法?

Have you tried EnumerateFiles method of DirectoryInfo class?

正如 MSDN 所说

EnumerateFilesGetFiles 方法的区别如下:使用EnumerateFiles,就可以开始枚举集合了返回整个集合之前的 FileInfo 对象;当你使用 GetFiles,您必须等待 FileInfo 对象的整个数组在您可以访问数组之前返回.因此,当你处理许多文件和目录,EnumerateFiles 可以更多高效.

The EnumerateFiles and GetFiles methods differ as follows: When you use EnumerateFiles, you can start enumerating the collection of FileInfo objects before the whole collection is returned; when you use GetFiles, you must wait for the whole array of FileInfo objects to be returned before you can access the array. Therefore, when you are working with many files and directories, EnumerateFiles can be more efficient.

这篇关于从包含大量文件的目录中检索文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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