本文主要是介绍获取某一扩展名的文件集合,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/// 获取某一扩展名的文件集合
/// </summary>
/// <param name="dictoryName">目录名</param>
/// <param name="fiterName">扩展名</param>
/// <returns>文件名集合</returns>
public List<string> Search(string dictoryName, string fiterName)
{
List<string> ViewFileNameLst = new List<string>();
if (!Directory.Exists(dictoryName))
{
return ViewFileNameLst;
}
DirectoryInfo dirInfo = new DirectoryInfo(dictoryName);
FileInfo[] fileInfs = dirInfo.GetFiles("*.*",SearchOption.AllDirectories);
foreach (FileInfo fInfo in fileInfs)
{
//过滤指定后缀名文件
if (fInfo.Extension.Equals(fiterName))
{
ViewFileNameLst.Add(System.IO.Path.GetFileNameWithoutExtension(fInfo.FullName));
}
}
return ViewFileNameLst;
}
/// </summary>
/// <param name="dictoryName">目录名</param>
/// <param name="fiterName">扩展名</param>
/// <returns>文件名集合</returns>
public List<string> Search(string dictoryName, string fiterName)
{
List<string> ViewFileNameLst = new List<string>();
if (!Directory.Exists(dictoryName))
{
return ViewFileNameLst;
}
DirectoryInfo dirInfo = new DirectoryInfo(dictoryName);
FileInfo[] fileInfs = dirInfo.GetFiles("*.*",SearchOption.AllDirectories);
foreach (FileInfo fInfo in fileInfs)
{
//过滤指定后缀名文件
if (fInfo.Extension.Equals(fiterName))
{
ViewFileNameLst.Add(System.IO.Path.GetFileNameWithoutExtension(fInfo.FullName));
}
}
return ViewFileNameLst;
}
这篇关于获取某一扩展名的文件集合的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!