如何取得硬盘上所有某类文件的文件名,例如 *.mp3

CForce 2001-11-19 11:42:13
我用System.IO.Directory的方法+递归来写很慢,查得很慢。
...全文
66 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
CForce 2001-11-24
  • 打赏
  • 举报
回复
我顶!
kingsimba 2001-11-20
  • 打赏
  • 举报
回复
慢就是你算法的问题了,完全可以不用递归。以前学过两层while循环代替递归调用的方法,你可以试试。搜索硬盘上的所有文件本来就是很慢的工作。不过用递归浪费资源也太不值得了。
kingsimba 2001-11-20
  • 打赏
  • 举报
回复
System.IO.Directory namespace 里的GetFiles(string),可以用"*.mp3"通配符。还有些重载的函数,查查MSDN吧。

Gets the files in the specified directory.
public static string[] GetFiles(string);

Gets an array of file names matching the specified search criteria from the specified directory.
public static string[] GetFiles(string, string);

GetCurrentDirectory ----- Gets the current directory.
GetDirectories ----- Overloaded. Gets an array of directories in the current directory.
GetDirectoryRoot ----- Returns the root portion of the specified path.
CForce 2001-11-20
  • 打赏
  • 举报
回复
呵呵,“我用System.IO.Directory的方法+递归”
已经说明了我会用System.IO.Directory的方法,这点您不用再说了。我也知道用递归是慢的主要原因,不然我就不用在问题里特意告诉你了。
“两层while循环代替递归调用”的方法我不会,你写写代码来让我学学?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧