I want to find the size of file on disk on linux OS . I know command to do so: du -s -h
Is there any way to find it using c/c++ code ?
Yes, use the stat(2)
system call:
#include <sys/stat.h>
...
struct stat statbuf;
if (stat("file.dat", &statbuf) == -1) {
/* check the value of errno */
}
printf("%9jd", (intmax_t) statbuf.st_size);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.