C语言 定位 “下一个文件”

dttlove_ni 2008-09-09 12:00:52
一批按规则命名的文件。处理完第一个文件之后,再处理下一个文件,依此类推

C语言怎么查找定位下一个文件?
...全文
105 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
帅得不敢出门 2008-09-09
  • 打赏
  • 举报
回复
我有个 C++遍历文件夹下所有文件 不过当时用了MFC http://blog.chinaunix.net/u2/64540/showart_507870.html
wangdeqie 2008-09-09
  • 打赏
  • 举报
回复

//这是我以前写的,不知道楼主是不是这个意思?

//----------------------------------------------------------
//d盘下的my picture文件夹,比如里面包括:1.jpg,2.jpg,1.txt这三个文件
//1.txt里面的内容为:
//1.jpg *********
//2.jpg *********
//3.jpg *********
//4.jpg *********
//----------------------------------------------------------
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<io.h>
#include <process.h>
#include <memory.h>

void SearchFile(const char *);

int main()
{
printf("在.txt文件里查找.jpg文件:\n\n");

SearchFile("d:\\my picture");

printf("\n");
system("pause");
return 0;
}
void SearchFile(const char *dir)
{
FILE *fp;
char *str="aa";
char buff[256];
fp=fopen("d:\\my picture\\1.txt","r");
if (fp==NULL)
{
printf("can not oepn file\n");
}

struct _finddata_t ffblk;
char path[256];
sprintf(path,"%s\\*.jpg*",dir);
long done = _findfirst(path,&ffblk);
int find=0;

while (find==0)
{
if(strcmp(ffblk.name,".jpg"))
{
while(fgets(buff,256,fp)!=NULL)
{
if (strstr(buff,ffblk.name)!=NULL)
{
printf("%s",buff);
memset(buff,0,256);
}
}
fseek(fp,0,0);
}
find=_findnext(done,&ffblk);
}
_findclose(done);

printf("\n");
fclose(fp);
}
dttlove_ni 2008-09-09
  • 打赏
  • 举报
回复
处理可以说是遍历一遍。这一批按规则命名的文件的个数不确定。
lann64 2008-09-09
  • 打赏
  • 举报
回复
通常是把符合规则的文件名一次全部保存下来,再顺序操作。
xkyx_cn 2008-09-09
  • 打赏
  • 举报
回复
前面是怎么处理的?
puzzlesky 2008-09-09
  • 打赏
  • 举报
回复
没看懂

70,035

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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