Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How to find if a file is empty (http://www.go4expert.com/forums/file-empty-t23695/)

heidik 28Oct2010 15:19

How to find if a file is empty
 
Could anyone please show me a working example of how to find if a file exists but is empty or not?

Thanks

shabbir 28Oct2010 17:12

Re: How to find if a file is empty
 
What is your OS? In Windows read the file size and check if it is 0 or not but for Linux there will be no zero file size for even an empty file as far as I remember.

heidik 28Oct2010 19:11

Re: How to find if a file is empty
 
I am working on Linux.

shabbir 28Oct2010 19:49

Re: How to find if a file is empty
 
So then check the size of the empty file in your Linux and I guess it will be 4bytes or something but not sure.

If you read the file and get its size to be equal to your empty file size you assume it to be an empty file.

heidik 28Oct2010 19:54

Re: How to find if a file is empty
 
oh OK. Let me try this.

heidik 28Oct2010 20:55

Re: How to find if a file is empty
 
The getline(fileName,line) also reads the last line that is an empty line. Is there any way not to read that last empty line?

shabbir 29Oct2010 08:56

Re: How to find if a file is empty
 
Yes we can have multiple methods to see if the file is empty or not.


All times are GMT +5.5. The time now is 15:06.