本文介绍了如何从文件夹中读取.jpeg文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个文件夹中有一个文件夹有图片jpeg格式
如何逐个读取扩展名john.jpeg susan.jpeg xxx.jpeg里面的图片名称文件夹?
所以我需要john.jpeg例如我只想拿john
there is a folder this folder has pictures jpeg format
how to read extensions one by one john.jpeg susan.jpeg xxx.jpeg names of pictures inside a folder?
so I need john.jpeg for example I want to take only john
推荐答案
string[] dirs = Directory.GetFiles(@"c:\", "*.jpeg");
public void GetFiles(string path)
{
if (File.Exists(path))
{
// This path is a file
ProcessFile(path);
}
else if (Directory.Exists(path))
{
{
// This path is a directory
ProcessDirectory(path);
}
}
public void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
ProcessFile(fileName);
// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}
public string ProcessFile(string path)
{
FileInfo fi = new FileInfo(path);
string sExtension = fi.Extension;
return sExtension;
}
这篇关于如何从文件夹中读取.jpeg文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!