linux中使用opdir_readdir读取目录中的信息
2016-02-19 16:26
831 查看
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2)
{
printf("usage: ls directory_name\n");
exit(-1);
}
if ((dp = opendir(argv[1])) == NULL)
{
printf("can't open [%s]\n", argv[1]);
exit(-2);
}
printf("==name==\t==type==\n");
while ((dirp = readdir(dp)) != NULL)
printf("%s\t%d\n", dirp->d_name,dirp->d_type);
closedir(dp);
exit(0);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *dirp;
if (argc != 2)
{
printf("usage: ls directory_name\n");
exit(-1);
}
if ((dp = opendir(argv[1])) == NULL)
{
printf("can't open [%s]\n", argv[1]);
exit(-2);
}
printf("==name==\t==type==\n");
while ((dirp = readdir(dp)) != NULL)
printf("%s\t%d\n", dirp->d_name,dirp->d_type);
closedir(dp);
exit(0);
}
相关文章推荐
- Linux初始root密码设置
- Linux:alias 起别名
- windows用crt免密码登录linux系统
- 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之一
- linux下的制作静态库并使用它
- linux下的第一个C程序及其编译方法
- linux软链接和硬链接的区别
- linux文件去重
- linux 下实用的命令
- Linux禁止root账户远程登录
- linux笔记_文件搜索命令
- Linux定时任务Crontab详解
- 自己平时用到的linux命令
- linux C gbk utf-8编码转换
- linux内嵌汇编语言
- 在CentOS_RHEL 6上安装Metasploit的框架
- Linux 查看进程
- linux获取外网ip
- linux vi编辑常用命令
- Linux TLS - pthread_setspcific