浏览一个目录
来源:互联网 发布:下载2345软件大全 编辑:程序博客网 时间:2024/06/12 10:09
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <stddef.h>
int main()
{
DIR *dp;
struct dirent *entry;
struct stat st;
char *dirp = "/home/rong";
if((dp = opendir(dirp)) == NULL)
{
perror("open /home:");
return -1;
}
chdir(dirp);
perror("/home");
while(entry = readdir(dp))
{
if(stat(entry->d_name,&st)!=-1)
{ printf("%s\t",entry->d_name);
if(st.st_mode&S_IFMT==S_IFDIR)
printf("dir\t");
else if(st.st_mode&S_IFMT==S_IFBLK)
printf("blk dievce\t");
else if(st.st_mode&S_IFMT==S_IFCHR)
printf("char dievce\t");
else if(st.st_mode&S_IFMT==S_IFREG)
printf("ord file\t");
//else
//printf("unknown file\n");
}
}
close(dp);
return 0;
}
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <stddef.h>
int main()
{
DIR *dp;
struct dirent *entry;
struct stat st;
char *dirp = "/home/rong";
if((dp = opendir(dirp)) == NULL)
{
perror("open /home:");
return -1;
}
chdir(dirp);
perror("/home");
while(entry = readdir(dp))
{
if(stat(entry->d_name,&st)!=-1)
{ printf("%s\t",entry->d_name);
if(st.st_mode&S_IFMT==S_IFDIR)
printf("dir\t");
else if(st.st_mode&S_IFMT==S_IFBLK)
printf("blk dievce\t");
else if(st.st_mode&S_IFMT==S_IFCHR)
printf("char dievce\t");
else if(st.st_mode&S_IFMT==S_IFREG)
printf("ord file\t");
//else
//printf("unknown file\n");
}
}
close(dp);
return 0;
}
0 0
- 浏览一个目录
- Tomcat禁止目录浏览
- 禁止目录浏览
- Tomcat 禁止目录浏览
- apache禁止浏览目录
- resin 禁止浏览目录
- 关掉 lighttpd 目录浏览
- Apache关闭目录浏览
- 递归浏览目录
- 浏览目录对话框
- 浏览目录范例程序
- 浏览特定目录
- resin4 指定浏览目录
- [WINCE]浏览指定目录
- apache目录浏览设置
- apche 禁止 浏览 目录
- Apache关闭目录浏览
- 浏览目录创建别名
- c_函数指针
- Android中的命名规范
- LightOJ1074 SPFA判负环
- static简介
- 堆的应用!--求第k大数
- 浏览一个目录
- LightOJ 1295 Lighting System Design (排序+dp)
- JS前端框架10 Extjs5 使用Tips
- JQuery显示隐藏一个按钮
- 如何入侵目标的网络DIY指南
- 数据库锁
- 使用history.back()出现"警告: 网页已过期的解决办法"
- OC_类和对象
- 国内外BaaS服务盘点