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

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

问题描述

我有一个包含支持* .wav格式的近1400万的音频采样目录。

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说

EnumerateFiles 的GetFiles 方法的区别如下:当你
  使用 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天全站免登陆