找到在文件夹中的某些扩展名的文件 [英] Find a file with a certain extension in folder

查看:105
本文介绍了找到在文件夹中的某些扩展名的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个文件夹路径(如C:\\文件夹随机),我怎么能找到一个文件保存一定的扩展,如TXT?我想我必须做目录中的* .TXT搜索,但我不知道我怎么想我开始摆在首位此搜索。

Given a folder path (like C:\Random Folder), how can I find a file in it that holds a certain extension, like txt? I assume I'll have to do a search for *.txt in the directory, but I'm not sure how I'm suppose to start this search in the first place.

推荐答案

System.IO.Directory 类和静态方法的GetFiles 。它有一个接受路径和搜索模式的超载。例如:

Look at the System.IO.Directory class and the static method GetFiles. It has an overload that accepts a path and a search pattern. Example:

 string[] files = System.IO.Directory.GetFiles(path, "*.txt");

这篇关于找到在文件夹中的某些扩展名的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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