#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#define BUF_SIZE 1024
void test_dir(char *dir)
{
DIR *dirp;
struct dirent *dp;
struct stat statbuf;
char path[BUF_SIZE];
int n;
if ((dirp = opendir(dir)) == NULL) {
printf("open %s failed\r\n", dir);
return;
}
while ((dp = readdir(dirp)) != NULL) {
n = strlen(dir);
if (dir[n-1] == '/') {
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#define BUF_SIZE 1024
void test_dir(char *dir)
{
DIR *dirp;
struct dirent *dp;
struct stat statbuf;
char path[BUF_SIZE];
int n;
if ((dirp = opendir(dir)) == NULL) {
printf("open %s failed\r\n", dir);
return;
}
while ((dp = readdir(dirp)) != NULL) {
n = strlen(dir);
if (dir[n-1] == '/') {

这段代码展示了如何使用C语言遍历指定目录及其子目录,打印出所有非隐藏的文件和目录。通过opendir()、readdir()、lstat()等函数获取并处理文件系统信息。
最低0.47元/天 解锁文章
4784

被折叠的 条评论
为什么被折叠?



