目录IO:
1.opendir
DIR *opendir(const char *name);
功能:打开目录文件
参数:
name:目录文件的路径
返回值:
成功返回目录流指针
失败返回NULL
2.closedir
int closedir(DIR *dirp);
功能:关闭目录流指针
参数:
dirp:目录流指针
返回值:
成功返回0
失败返回-1
3.readdir
struct dirent *readdir(DIR *dirp);
功能:从目录流中读取下一个目录项(一个文件)的信息
参数:
dirp:目录流指针
返回值:
成功返回目录项对应文件的信息
失败返回NULL
读到目录末尾返回NULL
struct dirent {
ino_t d_ino; /* Inode number */
off_t d_off; /* Not an offset; see below */
unsigned short d_reclen; /* Length of this record */
unsigned char d_type; /* Type of file; not supported
by all filesystem types */
char d_name[256]; /* Null-terminated filename */
};
d_ino:inode节点
d_off:目录项偏移量
d_reclen:当前目录项长度
d_type:文件类型
d_name:文件名字
4.mkdir
int mkdir(const char *pathname, mode_t mode);
功能:创建一个目录文件
参数:
pathname:目录路径
mode:权限
返回值:
成功返回0
失败返回-1
r:是否能够查看目录下文件
w:是否能在目录中创建新文件
x:是否能够进入目录文件
5.rmdir
int rmdir(const char *pathname);
功能:删除一个空目录文件
参数:
pathname:目录的路径
返回值:
成功返回0
失败返回-1
6.getcwd
char *getcwd(char *buf, size_t size);
功能:获得调用该函数的程序所在的绝对路径
参数:
buf:存放路径字符串空间首地址
size:最大允许存放字符串个数
返回值:
成功返回存放字符串空间首地址
失败返回NULL
7.chdir
int chdir(const char *path);
功能:切换当前的工作路径
参数:
path:路径
返回值:
成功返回0
失败返回-1
插入知识点:
时间函数:
1.time
time_t time(time_t *tloc);
功能:获得1970-1-1 0:0:0秒到现在的秒数
参数:
tloc:存放秒数空间的首地址
返回值:
成功返回秒数
失败返回-1
2.localtime
struct tm *localtime(const time_t *timep);
功能:将1970-1-1 0:0:0秒数转换为本地时间
参数:
timep:存放秒数空间首地址
返回值:
成功返回本地时间结构体指针
失败返回NULL
struct tm {
int tm_sec; /* Seconds (0-60) */
int tm_min; /* Minutes (0-59) */
int tm_hour; /* Hours (0-23) */
int tm_mday; /* Day of the month (1-31) */
int tm_mon; /* Month (0-11) */
int tm_year; /* Year - 1900 */
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
int tm_isdst; /* Daylight saving time */
};
本期的知识点分享就到这里结束了,这也是博主在自学过程中整理的笔记,其中有自己一些见解,希望可以帮到小伙伴们,欢迎评论区留言哦!