linux 文件管理相关函数介绍
2012-11-24 18:25
393 查看
fileno函数:文件流(FILE*)->文件描述符
#include <stdio.h>
int main(void)
{
FILE * fp; //文件流
int fd; //文件描述符
fp=fopen("/home/yaoyin/bin/test/1.c","r");
fd=fileno(fp);
printf("fd=%d\n",fd);
fclose(fp);
return 0;
}
结果: fd=3(0 stdin 1 stdout 2 stderr 未被使用的最小的描述符=3)
扫描目录:
头文件dirent.h
DIR:结构体,用于操作目录,不可改变之
dirent:结构体,与DIR相同,可操作之
Directory entries themselves are returned in dirent structures,also declared in dirent.h,
because one should never alter the fields in the DIR structure directly.
相关函数:opendir,closedir,readdir,telldir,seekdir
DIR *opendir(const char *name);
关键函数:readdir
struct dirent *readdir( DIR * dirp)
return a pointer to a structure detailing the next directory entry in the directory stream drip.
successive calls return further directory entries.
On error,or at the end of the directory,return NULL.
当其他进程创建、删除文件的同时,使用readdir,不能保证列举出所有的文件和子目录。
//1.c
int main(int argc,char *argv[])
{
//
}
gcc 1.c -o test
./test arg1 arg2
结果:argc=3 argv指向{"test","arg1","arg2"}
#include <stdio.h>
int main(void)
{
FILE * fp; //文件流
int fd; //文件描述符
fp=fopen("/home/yaoyin/bin/test/1.c","r");
fd=fileno(fp);
printf("fd=%d\n",fd);
fclose(fp);
return 0;
}
结果: fd=3(0 stdin 1 stdout 2 stderr 未被使用的最小的描述符=3)
扫描目录:
头文件dirent.h
DIR:结构体,用于操作目录,不可改变之
dirent:结构体,与DIR相同,可操作之
Directory entries themselves are returned in dirent structures,also declared in dirent.h,
because one should never alter the fields in the DIR structure directly.
相关函数:opendir,closedir,readdir,telldir,seekdir
DIR *opendir(const char *name);
关键函数:readdir
struct dirent *readdir( DIR * dirp)
return a pointer to a structure detailing the next directory entry in the directory stream drip.
successive calls return further directory entries.
On error,or at the end of the directory,return NULL.
当其他进程创建、删除文件的同时,使用readdir,不能保证列举出所有的文件和子目录。
//1.c
int main(int argc,char *argv[])
{
//
}
gcc 1.c -o test
./test arg1 arg2
结果:argc=3 argv指向{"test","arg1","arg2"}
相关文章推荐
- 文件系统管理 之 Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍
- 嵌入式学习28(linux系统函数之文件、文件夹管理相关函数)
- Linux系统管理.Raid的配置文件说明及相关命令介绍
- (十七)文件操作——其余相关函数的介绍、以及递归输出目录中的文件列表
- Linux文件相关函数
- Linux服务器开发之:chmod()函数,chmod命令,以及文件屏蔽umask命令,程序修改umask,详细介绍+案例演示
- Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍 推荐
- Linux应用程序开发笔记->文件编程之系统调用方式相关函数
- linux和windows互传文件、用户密码的配置文件、用户组和用户的管理的介绍
- linux磁盘与文件系统管理相关命令
- linux文件操作相关函数
- Linux密码相关文件介绍
- linux下用户和组相关的文件及相关管理命令
- Linux之网络管理 (4)相关基本配置文件
- Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍
- Linux基础--介绍 文件的管理与编辑 正则表达式的应用
- [转载] Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍
- Linux 内核的文件 Cache 管理机制介绍-ibm
- Linux下静态库_库的基本概念;如何生成静态库动态库;nm查看库中包含那些函数、ar生成静态库,查看库中包含那些.o文件、ldd查看程序依赖的.so文件;gcc/g++与库相关的参数-L,-l,-f
- Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍