您当前的位置: 首页 >  linux

柳鲲鹏

暂无认证

  • 0浏览

    0关注

    4642博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

LINUX用C检查文件的大小的代码

柳鲲鹏 发布时间:2018-09-13 17:15:49 ,浏览量:0

  推荐的方法:

#include 

unsigned long get_file_size(const char *pPath)
{
    unsigned long nFileSize = -1;
    struct stat statbuff;

    if (stat(pPath, &statbuff) >= 0)
    {
        nFileSize = statbuff.st_size;
    }
    return nFileSize;
}  

 

  另外一种方法:

unsigned long get_file_size2(const char *pPath)
{
    unsigned long nFileSize = -1;
    FILE *pFile;

    pFile = fopen(pPath, "r");
    if(pFile)
    {
        fseek(pFile, 0L, SEEK_END);
        nFileSize = ftell(pFile);
        fclose(pFile);
    }

    return nFileSize;
}  

 

关注
打赏
1665724893
查看更多评论
立即登录/注册

微信扫码登录

0.0495s