checking a file size i C

Posted on 2004-04-04
Medium Priority
Last Modified: 2011-09-20
How could i check to see whether a file size > or ==  to some value?
(in C language)
Question by:achille67
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Accepted Solution

Alf666 earned 80 total points
ID: 10753881
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.

Author Comment

ID: 10753925
thanks  Alf666,
you gave me my first exciting answer through this website,
thanks again man.

Expert Comment

ID: 10753949
Is this the reason why you offer so few points ? ;-)

Author Comment

ID: 10753966
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 :-)


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question