• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

XiaoXiaoli

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

c_文件

我们对目录和文件的常见操作包括,创建、删除、移动、获取大小、获取名称、获取路径。

 

使用c语言实现功能,在Linux环境下通过读取文件信息,获取文件大小。

使用函数stat,结构体struct stat,调用结构体中的成员st_size。

#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>

int file_size(const char *filePath){
        struct stat statbuf;
        stat(filePath, &statbuf);
        return statbuf.st_size;
}

int main(void){
        int size = file_size("./get_file_size.c");
        printf("%d\n", size);
        return 0;
}

 

posted on 2020-12-27 16:22  XiaoXiaoli  阅读(63)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3