| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 561 人关注过本帖
标题:[求助]递归显示输入路径下所有文件目录
只看楼主 加入收藏
wen2204
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2007-7-18
收藏
 问题点数:0 回复次数:0 
[求助]递归显示输入路径下所有文件目录

此程序功能是任意输入一个路径后,显示路径下面所有的子目录
可是运行的时候总是出现错误:cpp(89) : error C2064: term does not evaluate to a function。
请高手们帮我解答一下啊
#include<stdio.h>
#include<conio.h>
#include<io.h>
#include<stdlib.h>
#include<string.h>

void subfile(char *filepath);//定义子目录处理函数

void main(void)
{
FILE *fp;
FILE *fq;
struct _finddata_t filefind;
char path[250];
char subpath[250];
scanf("%s",path); //输入要显示的路径
strcpy(subpath,path);
strcat(path,"/*.*");

if((fp=fopen("path","w"))==NULL) //不能打开输入路径下的目录
{
printf("Can not open the file in the path!\n");
getch();
exit(1);
}

long handle=_findfirst(path,&filefind);

if(handle==-1) //在输入路径下没有文件存在
{
printf( "NO files exist in the path !\n" );
_getch();
exit (1);
}
printf("The directory listing of files is:\n");

while(-1 != _findnext(handle,&filefind)) //输入路径下存在子目录
{
strcat(subpath,filefind.name);

if((fq=fopen("subpath","w"))==NULL) //不能打开此路径
{
return;
}

else
{
subfile(subpath);//该子目录可以打开,进入子目录处理
}

}

_findclose(handle);
_getch();
exit(1);
}

//子目录的处理函数
void subfile(char *filepath)
{
FILE *fp;
char subpath[250];//如果是文件夹,作为路径找其中的文件
char path[250]; //如果下面还有目录,作为下级目录的总路径
char fpath[250]; //如果不是文件夹,此为显示的文件名
strcpy(subpath,filepath);
strcpy(path,filepath);
strcpy(fpath,filepath);
strcat(subpath,"/*.*");
struct _finddata_t subfile;//定义文件目录下的子目录
long handle=_findfirst(subpath,&subfile);

if(-1==handle) //此目录下面已没有子目录
{
printf("%s\n",fpath); //显示目录名
return ;
}

while(-1 != _findnext(handle,&subfile)) //目录下面包含子目录
{
strcat(path,subfile.name);

if((fp=fopen("subpath","w"))==NULL) //不能打开此路径
{
return;
}

else
{
subfile(path); //如果目录还能打开,递归显示子目录
}
}

_findclose(handle);
}

[此贴子已经被作者于2007-7-24 11:36:27编辑过]

搜索更多相关主题的帖子: 递归 路径 目录 文件 
2007-07-24 11:34
快速回复:[求助]递归显示输入路径下所有文件目录
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011464 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved