求助~~~在线等待,分不是问题,答对了要多少给多少,请各位高手帮忙!!!!!

cuistar 2003-09-03 09:43:30
就是给定一个目录,列出其中的所有文件(包括子目录下的文件),用对话框实现此功能~~~~~~~~要VC源程序代码(包括对话框函数对类函数的调用)
...全文
84 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjq8086 2003-09-05
  • 打赏
  • 举报
回复
CFileFind里封装的好像也是上面的API,不过只能搜索当前路径, 要想实现搜索整个目录还要类似上面的递归处理一下,你自己去改写吧:)
cuistar 2003-09-04
  • 打赏
  • 举报
回复
谢谢高手,请问有没有用CfileFind写的代码???
zjq8086 2003-09-03
  • 打赏
  • 举报
回复
算了,那么容易找到了,给你吧

// SearchDir.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Windows.h>
#include <malloc.h>

typedef bool (*DisposeFile)(char *, char * ); //函数指针返回0则表示接收搜索


bool SearchDir(char * CurDir, DisposeFile dispose);
bool showname(char *dir, char * FileName);

int finename = 0;

int main(int argc, char* argv[])
{
SearchDir("d:\\",showname);
printf("%d\n", finename);
return 0;
}

bool showname(char *dir, char * FileName)
{
finename ++;
printf("%s%s\n",dir, FileName);
return 1;
}

bool SearchDir(char * CurDir, DisposeFile dispose)
{
//传入的参数形式为:d:\www\
//返回值并没有意义,只是用来在递归里判断是否结束本次搜索
HANDLE fHandle;
WIN32_FIND_DATA FileData;
int i;
char *dir;

dir = (char *)malloc(MAX_PATH + strlen(CurDir) + 2);
strcpy(dir,CurDir);
strcpy(dir + strlen(CurDir),"*");

fHandle = FindFirstFile(dir, &FileData);

if (fHandle == INVALID_HANDLE_VALUE)
{
free(dir);
return 1;
}
i = 1;
while (i != 0)
{
if (FileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
if (strcmp(FileData.cFileName,".") != 0 && strcmp(FileData.cFileName,"..") != 0)
{
strcpy(dir,CurDir);
strcpy(dir + strlen(CurDir), FileData.cFileName);
strcpy(dir + strlen(CurDir) + strlen(FileData.cFileName), "\\");
if (!SearchDir (dir, dispose))
{
free(dir);
return 0;
}
}
}
else
{
if (!dispose(CurDir, FileData.cFileName))
{
free(dir);
return 0;
}
}
i = FindNextFile(fHandle, &FileData);
}
FindClose(fHandle);
free(dir);
return 1;
}
zjq8086 2003-09-03
  • 打赏
  • 举报
回复
我以前做过,给多少分?

69,382

社区成员

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

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