在整台计算机中搜索指定的文件 [英] Searching entire computer for specified file

查看:44
本文介绍了在整台计算机中搜索指定的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以搜索整台计算机并获得指定文件的完整文件路径(给定要匹配的文件名?)?

Is there a way to search the entire computer and get the full file path of specified file, given a filename to match against?

如果在文本框中输入例如"file.dat",它会显示完整的文件路径(如果存在)吗?

If you enter for example "file.dat" in textbox it show you full file path if it exist?

推荐答案

查看 System.IO 中的 Directory 类.

使用哪种解决方案,请避免使用 GetFiles(),而应使用 EnumerateFiles(),因为 EnumerateFiles()

Whichever solution you use, avoid using GetFiles() instead use EnumerateFiles() since EnumerateFiles() is recommended for large arrays. (In your case the entire C drive)

根据MSDN文档:

当处理大量目录和文件的集合时,可枚举的集合提供的性能要优于数组.

Enumerable collections provide better performance than arrays when you work with large collections of directories and files.

这篇关于在整台计算机中搜索指定的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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