linux c 下如何获得目录下的文件数目
更新时间:2023-12-06 07:49:01 阅读量: 教育文库 文档下载
- linux系统推荐度:
- 相关推荐
linux c 下如何获得目录下的文件数目
int main(int argc, char **argv) {
DIR * pdir;
struct dirent * pdirent; struct stat f_ftime;
int fcnt;/*文件数目统计*/ pdir=opendir(\ if(pdir==NULL) { return(-1); } fcnt=0;
for(pdirent=readdir(pdir);pdirent!=NULL;pdirent=readdir(pdir)) {
if(strcmp(pdirent->d_name,\
if(stat(pdirent->d_name,&f_ftime)!=0) return -1 ;
if(S_ISDIR(f_ftime.st_mode)) continue; /*子目录跳过*/ fcnt++;
printf(\文件:%s\\n\ }
printf(\文件总数%d\\n\ closedir(pdir); return 0; }
#include
void printdir(char *dir, int depth) {
DIR *dp;
struct dirent *entry; struct stat statbuf;
if((dp = opendir(dir)) == NULL) {
fprintf(stderr, \ return; }
chdir(dir);
while((entry = readdir(dp)) != NULL) { lstat(entry-> d_name,&statbuf); if(S_ISDIR(statbuf.st_mode)) {
/**//* Found a directory, but ignore . and .. */ if(strcmp( \ strcmp( \ continue;
printf( \ /**//* Recurse at a new indent level */ printdir(entry-> d_name,depth+4); }
else printf( \ }
chdir( \ closedir(dp); }
/**//* Now we move onto the main function. */
int main(int argc, char* argv[]) {
char *topdir, pwd[2]= \ if (argc != 2) topdir=pwd; else
topdir=argv[1];
printf( \ printdir(topdir,0); printf( \
exit(0); }
正在阅读:
区水利局2021年综合工作年度总结和2022年工作思路08-02
Protel制板总结07-08
线路距离保护课程设计03-06
PLC习题参考答案05-04
自评报告和施工总结05-05
中国式改良型水溶液全循环法尿素生产工艺06-11
华工电力电子随堂练习题库11-09
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 数目
- 获得
- 文件
- 目录
- 如何
- linux
- 新员工安全培训手册
- 吊车性能手册 - 图文
- 八段锦各式的功理与作用、动作要领、易犯错误和纠正方法
- 南安“低碳经济与循环经济”网上培训考试答案(二)多选题
- 如何识别安全帽和安全带的有效期 - 图文
- 丰润中学校旧址初考
- 病理考博问答题
- 2018年童车行业现状及发展趋势分析(目录)
- 羽毛球理论试题库
- 上海版牛津英语8B Unit4 知识点梳理&配套双基
- 中国石油大学安全工程2015春季第二阶段在线作业
- 《红与黑》中的心理描写特点
- 税法A卷
- 物化,第1章 热力学第一定律 - 补充练习题
- 人教版高中地理《工业地域的形成与发展》单元测试(含答案精析)
- 西门子车床车床指令集
- 学生安全教育的定位、职责与标准 - 图文
- 师宗县长青煤矿掘进工作面作业规程1935水平北翼掘进工作面(已改)
- 大学电路复习选择题
- 2015河北省对口高考计算机理论考试试题及答案