如何使用C语言搜索指定目录下的所有文件?
2013-03-19 11:26
597 查看
#include <stdio.h>
#include <dirent.h>
#include <string.h>
void main(int argc,char *argv[])
{
DIR *directory_pointer;
struct dirent *entry;
struct FileList
{
char filename[64];
struct FileList *next;
}start,*node;
if (argc!=2)
{
printf( "Must specify a directory\n ");
exit(1);
}
if ((directory_pointer=opendir(argv[1]))==NULL)
printf( "Error opening %s\n ",argv[1]);
else
{
start.next=NULL;
node=&start;
while ((entry=readdir(directory_pointer))!=NULL)
{
node-> next=(struct FileList *)malloc(sizeof(struct FileList));
node=node-> next;
strcpy(node-> filename,entry-> d_name);
node-> next=NULL;
}
closedir(directory_pointer);
node=start.next;
while(node)
{
printf( "%s\n ",node-> filename);
node=node-> next;
}
}
}
#include <dirent.h>
#include <string.h>
void main(int argc,char *argv[])
{
DIR *directory_pointer;
struct dirent *entry;
struct FileList
{
char filename[64];
struct FileList *next;
}start,*node;
if (argc!=2)
{
printf( "Must specify a directory\n ");
exit(1);
}
if ((directory_pointer=opendir(argv[1]))==NULL)
printf( "Error opening %s\n ",argv[1]);
else
{
start.next=NULL;
node=&start;
while ((entry=readdir(directory_pointer))!=NULL)
{
node-> next=(struct FileList *)malloc(sizeof(struct FileList));
node=node-> next;
strcpy(node-> filename,entry-> d_name);
node-> next=NULL;
}
closedir(directory_pointer);
node=start.next;
while(node)
{
printf( "%s\n ",node-> filename);
node=node-> next;
}
}
}
相关文章推荐
- 如何使用c语言递归地列出linux系统的所有目录和文件
- 使用sh脚本如何替换指定目录下所有文件中的指定字符串
- linux下使用c语言删除指定目录下所有文件
- linux下使用c语言删除指定目录下所有文件
- 使用grep指令在当前目录下所有文件中搜索指定文本
- 搜索目录下所有文件内容是否包含指定的关键词
- 搜索指定目录下的所有文件或者指定文件(可用于多级目录)
- C# 使用 DirectoryInfo 递归指定目录中的所有目录及文件
- 如何读取一个文件夹下的所有图像文件,并制作负样本到指定目录
- 搜索指定目录下的指定后缀名字的所有文件的内容
- Linux下如何遍历指定目录下的所有文件并删除指定天数之前创建的文件
- 市面上所有号称"虚拟机","防火墙"的实时监控杀毒软件无一不是使用的IFSHOOK技术.但是同时也有一些朋友不断写MAIL给我打听如何实现读写的监控.下面给出用VTOOLSD写的代码.也就是所有实时杀毒软件的奥秘.同时,很多拦截文件操作的软件,例如对目录加
- C#使用线程加载指定目录下的所有子目录和文件名称到TreeView中
- 利用Dataview实现搜索指定目录下的所有文件,以指定的条件排序(可以按文件名升降序,最后修改时间升降序)
- 使用Python批量替换指定目录所有文件中的指定文本
- Linux下使用find查找文件内容,跳过所有目录名成和指定子目录的方法
- 使用线程加载指定目录下的所有子目录和文件名称到TreeView中
- C#使用线程加载指定目录下的所有子目录和文件名称到TreeView中
- 黑马程序员-列出一个目录中所有指定文件,使用FilenameFilter类
- 使用线程加载指定目录下的所有子目录和文件名称到TreeView中