获取文件大小函数

来源:互联网 发布:人人商城数据库表 编辑:程序博客网 时间:2024/06/03 19:39

方法一:

long filesize( char * pFileName )
{
    long int save_pos;
    long size_of_file;

    FILE * fp = fopen( pFileName ,"r+b" );


    /* Save the current position. */
    save_pos = ftell( fp );

    /* Jump to the end of the file. */
    fseek( fp, 0L, SEEK_END );

    /* Get the end position. */
    size_of_file = ftell( fp );

    /* Jump back to the original position. */
    fseek( fp, save_pos, SEEK_SET );

 

    fclose(fp);

    return( size_of_file );
}

 

方法二:

 

#include <io.h>

long filelen( char * pFileName )
{
 FILE * f = fopen( pFileName , "r+b");  

 int handle = fileno(f) ;
 
 long nlen = filelength( handle );

 fclose(f);

 return nlen;

}