#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
void print_usage(void)
{
printf("Usage: programe_name dir_name\n");
}
int main(int argc,char *argv[])
{
DIR * dp;
struct dirent *filename;
if (argc < 2)
{
print_usage();
exit(1);
}
dp = opendir(argv[1]);
if (!dp)
{
fprintf(stderr,"open directory error\n");
return 0;
}
while (filename=readdir(dp))
{
printf("filename:%s\n",filename->d_name);
}
closedir(dp);
return 0;
}
linux dirent.h 使用
最新推荐文章于 2024-09-13 22:10:27 发布