Linux下获取文件大小(程序)
2013-04-23 17:28
537 查看
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <error.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> /* Linux终端输入提示符下输入命令:man 2 stat stat, fstat, lstat - get file status [b]有点类似于exec函数族一样的,stat函数族。 [/b] int stat(const char* path, struct stat* buf); int fstat(int fd, struct stat* buf); int lstat(const char* path, struct stat* buf); struct stat { dev_t st_dev; // ID of device containing file ino_t st_ino; // inode number mode_t st_mode; // protection nlink_t st_nlink; // number of hard links uid_t st_uid; // user ID of owner gid_t st_gid; // group ID of owner dev_t st_rdev; // device ID (if special file) off_t st_size; // total size, in bytes blksize_t st_blksize; // blocksize for file system I/O blkcnt_t st_blocks; // number of 512B blocks allocated time_t st_atime; // time of last access time_t st_mtime; // time of last modification time_t st_ctime; // time of last status change }; */ int main(int arc, char* const argv[]) { struct stat fileInfo; if (stat("main.c", &fileInfo) == 0) printf("The file size: %d byte!\n", fileInfo.st_size); return 0; }
[b]总结:发现这个程序去掉#include <unistd.h>,也可以在Windows下运行。[/b]
[b]仔细一查,Winows也有sys/types.h和sys/stat.h文件,struct stat的定义也差不多。[/b]
[b]额,有点惊喜,Windows也遵循POSIX标准哈![/b]
相关文章推荐
- Linux下获取文件大小的方法
- linux下C获取文件的大小 .
- c++获取linux本地文件的大小
- Linux C 获取 文件的大小
- linux 获取文件大小
- linux下C++读取文件,获取文件大小。
- Linux 获取文件大小--C函数
- 建议linux下使用stat()获取文件大小
- 在Linux下获取当前运行程序可执行文件全路径(不使用real_path()函数)
- Linux下获取文件大小的方法
- Linux下获取文件大小的方法
- linux下C获取文件的大小
- linux c 下获取文件大小
- LINUX C获取文件大小
- Linux下获取文件大小,检索目录函数
- linux获取文件大小[c]
- Linux下C获取文件的大小
- linux 获取文件大小
- Linux 获取文件大小--C函数
- Linux平台 获取程序依赖文件