<求助>急!!哪位高手指点下~关于文件搜索功能实现~

aduelone 2007-01-26 01:51:12
如何用C语言编写?先输入一个字符串,如“mp3”,查找当前路径下的所有mp3的
文件(包含子目录下),并把所有的mp3的路径显示出来!!! #include <sys pes.h>
#include <sys/stat.h>
#include <dirent.h>
#include <pwd.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

#define LENGTH 256

int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
static char *current_dir;
static char *filename;
int length;
if(argc==1)
{
printf("Please input you want to find type !!\n");
return 0;
}
if(argc==2)
{
current_dir=(char *)getcwd(current_dir,LENGTH);
filename=argv[1]; } dp=opendir(current_dir);
while((dirp=readdir(dp))!=NULL)
{ if (strcmp(dirp->d_name,filename)==0)
{
printf("%s/%s\n",current_dir,filename);
}
}
closedir(dp);
exit(0); } 出现 "/" "t" "y" 就是小太阳 命令行输入一个文件类型,找出所有这个类型的文件(包括子目录),输出这些文件 上面是我自己写的程序,怎么实行不了了.?
...全文
342 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wolf0403 2007-01-26
  • 打赏
  • 举报
回复
当前目录的话 readdir 足矣。递归可以选用 ftw 函数。
m_nNightmire 2007-01-26
  • 打赏
  • 举报
回复
LZ是做练习用的吧?能详细说明一下问题所在么?
是输出错误?还是编译不通过?
我这里的工具只有VC6.0,TC2.0,上面的几个头文件都没有
aduelone 2007-01-26
  • 打赏
  • 举报
回复
Wolf0403(废人)(Leading to nowhere...)

是么?我想要把所有的mp3的路径显示出来,该怎么弄啊?谢谢~~
m_nNightmire 2007-01-26
  • 打赏
  • 举报
回复
开发环境说一下,谢谢
Wolf0403 2007-01-26
  • 打赏
  • 举报
回复
你的程序只比较了当前目录下的文件名..你在期待什么?

15,447

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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