当前位置:网站首页>客户端与服务器通信项目5:C语言实现ls命令
客户端与服务器通信项目5:C语言实现ls命令
2022-04-22 07:43:00 【黑子的ball】
12、实现Linux下的ls命令
char *ls(char *dirname)
{
Dir* dir_ptr; //创建目录指针
struct dirent* direntp; //存放目录信息的结构体
static char buf[BUFFER_SIZE] = {
0}; //用于存放文件列表信息
memset(buf, 0, BUFFER_SIZE);
//打开一个目录,失败时返回空指针
if((dir_ptr = opendir(dirname)) == NULL)
{
perror("opendir");
}
else
{
//读目录,一次返回目录的子项
while((direntp = readdir(dir_ptr)) != NULL)
{
if(strcmp(direntp->d_name, ".") != 0 && strcmp(direntp->d_name, ".")
{
//若目录下文件不为空,诸葛读取文件信息
strcat(buf, direntp->d_name);
strcat(buf, "\n");
}
}
printf("%s\n", buf);
}
//关闭文件目录
close buf;
}
版权声明
本文为[黑子的ball]所创,转载请带上原文链接,感谢
https://blog.csdn.net/shark_93/article/details/120872872
边栏推荐
- 概率论笔记6.3抽样分布
- shell监控IBM MQ队列深度,10s扫描三次,有两次以上深度值超过5时,则输出队列名称和深度值。
- Airtest安装及介绍
- 236. 二叉树的最近公共祖先(Medium)
- sonic云真机入门教程
- ViewPager用法详细解析
- Make the airtest ide into a script and make the script run
- 工具类--正则-类型转换-DOM对象常用操作
- centos7安装MySQL8.0
- 【论文阅读】【3d目标检测】Voxel Set Transformer: A Set-to-Set Approach to 3D Object Detection from Point Clouds
猜你喜欢

shell笔记

129. 求根节点到叶节点数字之和(Medium)
![[Dahua cloud native] micro service chapter - service mode of five-star hotels](/img/fc/be18f39e4aa653efa8603ab63ff3f1.png)
[Dahua cloud native] micro service chapter - service mode of five-star hotels

第3关:节点状态检查、数据查看和更新

liunx基础—zabbix5.0监控系统安装部署

使⽤airtestIDE⽣成脚本,使⽤脚本运⾏

Redefine China's "core"

7-34 删除重复字符(set用法)&&7-35 统计字符出现次数(unordered_map)

spark sql 获取数组某index处元素

MySQL in-depth study (3-2): other database tuning strategies
随机推荐
第2关:多态
shell脚本学习笔记—循环语句
使⽤airtestIDE⽣成脚本,使⽤脚本运⾏
ospf四类,五类和七类LSA详解
Nacos Foundation (1): what is configuration center & introduction to Nacos
记录node中使用sequelize,自动生成表模型,链接操作数据库(以postgreSQL为例)
CPU的基本工作流程
Airtest installation and introduction
第3关:节点状态检查、数据查看和更新
Experiment 2: mathematical basis in Data Science
Flutter ListView 加载更多
微服务(分布式架构)
概率论笔记6.3抽样分布
每日一题冲刺大厂第十五天提高组 模
7-34 删除重复字符(set用法)&&7-35 统计字符出现次数(unordered_map)
Arm bare metal (IV) -- exceptions and interrupts
用OnLayoutChangeListener的方法解决getTop=0的问题
【优麒麟】22.04 LTS版本即将发布,终极预告来袭,你准备好了吗?
Tita performance treasure: eight mistakes made by managers in performance appraisal
Redefine China's "core"