checking file size 
Author Message
 checking file size

Hi all,

I'm trying to determine the size of an error log file created by the code
below . More precisely if it isn't empty.
Is there any simple way to do that?
It would be great also to be able to send it to a mail client if it wasn't
empty, a hint on this would be enough.

TIA
SC

////////////////////////code
 FILE *ptf;

 Error_file="D:\\Error_log.txt";
 ptf = fopen (Error_file, "w+");

switch(error_condition) {
case 1
    fputs("Error in......", ptf);
    break;
// several case statements folowing....

Quote:
}

 fflush(ptf);
 fclose(ptf);
////////////////////////code


Sun, 08 Dec 2002 03:00:00 GMT  
 checking file size

Quote:

> I'm trying to determine the size of an error log file  [...]
> Is there any simple way to do that?
> [...]
> ptf = fopen (Error_file, "w+");

1. Using FILE*

long save = ftell(ptf);
fseek(ptf, 0, SEEK_END);
long file_size = ftell(ptf);
fseek(ptf, save, SEEK_SET);

2. Using GetFileSize (Windows API, required for 64-bit files)

HANDLE hFile = CreateFile(
  Error_file,
  GENERIC_READ|GENERIC_WRITE,
  0,
  0,
  OPEN_EXISTING,
  0,
  0);
if (hFile != INVALID_HANDLE_VALUE)  
  DWORD file_size = GetFileSize(hFile, 0);



Sun, 08 Dec 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. HELP - How to check file size in DOS

2. Checking file sizes

3. Check the file size and number symbols in a file using C in Unix

4. FILE SIZE CHECKING FROM C PROGRAM

5. CHttpRequestParams::Render buffer size check is off by one

6. Memory size check

7. How to Check for size and create new db with ODBC

8. Checking size of array argument

9. How to check the size of an array when passed to a function

10. Array size checks

11. How to check the Hard Disk Size?

12. How to check the Hard disk size?

 

 
Powered by phpBB® Forum Software