1. 解题思路
二. 代码解析
- 头文件
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
- 主函数
int main(int argc, char const *argv[])
{
char file_path[100] = {
0};
printf("请输入你要查看的目录:\n");
scanf("%s", file_path);
tree(file_path);
return 0;
}
- 功能函数
//用来获取目录下的文件或者子目录
struct dirent *getdir(DIR *pDIR)
{
struct dirent *mdirent = NULL;
while (mdirent = readdir(pDIR))
{
//由于每个目录存在'.'和'..',所以需要避开
if (*(mdirent->d_name) != '.'