• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

checking a file size i C

How could i check to see whether a file size > or ==  to some value?
(in C language)
0
achille67
Asked:
achille67
  • 2
  • 2
1 Solution
 
Alf666Commented:
Just use the stat() or the fstat calls.

Example :

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

main(int argc, char **argv) {
struct stat buf ;
int size = 100 ; // octets

  stat("file_name", &buf);
  if (buf.off_t >= size) {
     // do what you have to do
  }
}

man 2 stat will give you more infos.
0
 
achille67Author Commented:
thanks  Alf666,
you gave me my first exciting answer through this website,
thanks again man.
Achille67.
0
 
Alf666Commented:
Is this the reason why you offer so few points ? ;-)
0
 
achille67Author Commented:
My bad dude, next time u will have a bigger one :-)
Also i thought modulo will answer this question so i gave a little point only :-)
for not answering my previous questions as i wanted :-)

Achille67
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now