#include <sys/stat.h>
#include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
int main(void)
{
DIR *dirp;
struct dirent *direntp;
char * path = "./pic";
if((dirp=opendir(path))==NULL)
{
printf("Open Directory %s Error: %s\n", path, strerror(errno));
exit(1);
}
while((direntp=readdir(dirp))!=NULL)
{
/* 给文件或目录名添加路径:argv[1]+"/"+direntp->d_name */
char dirbuf[512];
memset(dirbuf,0,sizeof(dirbuf));
strcpy(dirbuf,path);
strcat(dirbuf,"/");
strcat(dirbuf,direntp->d_name);
if(strstr(dirbuf,"bmp"))
{
printf("The file path is:%s\n",dirbuf);
}
}
closedir(dirp);
return 0;
}
C语言遍历一个文件夹下所有的bmp图像
最新推荐文章于 2024-01-22 10:34:41 发布