代码拉取完成,页面将自动刷新
同步操作将从 焦乐乐/dirsize 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<<<<<<< HEAD
#define _GNU_SOURCE
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
size_t total = 0;
//递归计算目录中各个文件的大小
void walk(char * path)
{
DIR* dp;
struct dirent* entry;
struct stat statbuf;
dp = opendir(path);
if (!dp)
{
perror("opendir");
return;
}
while((entry = readdir(dp)))
{
char * subpath;
if (!strcmp(entry->d_name, ".") ||
!strcmp(entry->d_name, ".."))
continue;
//printf("%s ", entry->d_name);
asprintf(&subpath, "%s/%s", path, entry->d_name);
if (lstat(subpath, &statbuf))
{
perror("lstat");
continue;
}
//printf("size: %lu\n", statbuf.st_size);
total += statbuf.st_size;
if (entry->d_type == DT_DIR)
{
printf("%s\n", subpath);
walk(subpath);
}
}
closedir(dp);
}
int main(int argc, char** argv)
{
char* path;
//./a.out dir
if (argc < 2)
{
path = ".";
}
else
{
path = argv[1];
}
walk(path);
printf("total: %lu\n", total);
return 0;
}
=======
#define _GNU_SOURCE
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
//目录大小
size_t total = 0;
//进入目录计算大小
void walk(char * path)
{
DIR* dp;
struct dirent* entry;
struct stat statbuf;
dp = opendir(path);
if (!dp)
{
perror("opendir");
return;
}
while((entry = readdir(dp)))
{
char * subpath;
if (!strcmp(entry->d_name, ".") ||
!strcmp(entry->d_name, ".."))
continue;
//printf("%s ", entry->d_name);
asprintf(&subpath, "%s/%s", path, entry->d_name);
if (lstat(subpath, &statbuf))
{
perror("lstat");
continue;
}
//printf("size: %lu\n", statbuf.st_size);
total += statbuf.st_size;
if (entry->d_type == DT_DIR)
{
printf("%s\n", subpath);
walk(subpath);
}
}
closedir(dp);
}
int main(int argc, char** argv)
{
char* path;
//./a.out dir
if (argc < 2)
{
path = ".";
}
else
{
path = argv[1];
}
walk(path);
printf("total: %lu\n", total);
return 0;
}
>>>>>>> 0bf51f640a62b580898431f1d9df84a91659e7b9
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。