当前位置:网站首页>Client and server communication project 5: LS command in C language
Client and server communication project 5: LS command in C language
2022-04-22 08:37:00 【Sunspot ball】
12、 Realization Linux Under the ls command
char *ls(char *dirname)
{
Dir* dir_ptr; // Create directory pointer
struct dirent* direntp; // A structure for storing directory information
static char buf[BUFFER_SIZE] = {
0}; // Used to store file list information
memset(buf, 0, BUFFER_SIZE);
// Open a directory , Return null pointer on failure
if((dir_ptr = opendir(dirname)) == NULL)
{
perror("opendir");
}
else
{
// Read the table of contents , Return the sub items of the directory at one time
while((direntp = readdir(dir_ptr)) != NULL)
{
if(strcmp(direntp->d_name, ".") != 0 && strcmp(direntp->d_name, ".")
{
// If the file in the directory is not empty , Zhuge reads file information
strcat(buf, direntp->d_name);
strcat(buf, "\n");
}
}
printf("%s\n", buf);
}
// Close the file directory
close buf;
}
版权声明
本文为[Sunspot ball]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220742497971.html
边栏推荐
猜你喜欢

Golang learning, pointer, loop control, correlation

The starting point of the final end of the 15th day of the sprint to the big factory

Mapbox设置官方地图语言为中文

The fluent modul class and JSON are converted to each other

【论文阅读】【3d目标检测】pvgnet

Fluent listview loads more

Flutter 判断网络可用性

100. 相同的树(Easy)

OLED显示驱动

Shell 命令脚本
随机推荐
Level 1: Inheritance
sonic云真机入门教程
OSPF class IV, class V and class VII LSA details
kubernetes—实战入门
accumulator
Asnotracking for efcore optimization
shell脚本学习笔记——shell对文件的操作sed
累加器
kubernetes—pod详解
地图裁剪器,可以将图片裁剪成瓦片数据,主要用途是将高清卫星图像裁剪成瓦片图,可以做离线地图的开发,基于墨卡托坐标
MaterialApp
Handler相关源码分析
Common sense and use of Oracle Database
236. 二叉树的最近公共祖先(Medium)
129. 求根节点到叶节点数字之和(Medium)
链表打印(链表反转输出)
Navicat Premium 导入SQL文件
构造函数与toString
第3关:节点状态检查、数据查看和更新
pictures rotating