用于读取目录的代码,如果目录大小​​超过20MB,则删除旧映像 [英] code to read the directory and delete the old images if directory size is more than 20MB

查看:71
本文介绍了用于读取目录的代码,如果目录大小​​超过20MB,则删除旧映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c读取目录大小?如果目录大小​​超过20MB,则应删除旧图像。请帮助我。

How to read the directory size using c? If directory size is greater than 20MB old images should be deleted. Please help me.

推荐答案

请参阅此stackoverflow帖子以获取代码以获取目录中的文件名列表:



http://stackoverflow.com/questions/ 12489 / how-do-get-a-directory-listing-in-c [ ^ ]



考虑到这一点,请使用stat ()获取每个文件的大小和年龄。



See this stackoverflow post for code to get a list of file names in a directory:

http://stackoverflow.com/questions/12489/how-do-you-get-a-directory-listing-in-c[^]

With that in mind, use stat() to get each file's size and age.

#include <sys/stat.h>
struct stat st = {0};
stat(filename, &st);
size = st.st_size;
time_t stamp = st.st_mtime;


这篇关于用于读取目录的代码,如果目录大小​​超过20MB,则删除旧映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆