(二)和菜鸟一起学unix之文件和目录 opendir ,closedir
2012-10-05 11:53
387 查看
man opendir:
NAME
opendir - open a directory
SYNOPSIS
头文件
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(const char *name);
DESCRIPTION
The opendir() function opens a directory stream corresponding to the
directory name, and returns a pointer to the directory stream. The
stream is positioned at the first entry in the directory.
RETURN VALUE
The opendir() function returns a pointer to the directory stream. On
error, NULL is returned, and errno is set appropriately.
ERRORS
EACCES Permission denied.
功能:opendir用来打开参数name制定的目录,并返回DIR*形态的目录流
返回值:成功返回目录流,失败返回NULL
man closedir:
NAME
closedir - close a directory
SYNOPSIS
#include <sys/types.h>
#include <dirent.h>
int closedir(DIR *dir);
DESCRIPTION
The closedir() function closes the directory stream associated with
dir. The directory stream descriptor dir is not available after this
call.
功能关闭一个 dir 所指的mulu
RETURN VALUE
The closedir() function returns 0 on success. On error, -1 is
returned, and errno is set appropriately.
返回值:成功返回0 错误返回-1
例子:
1 #include<stdio.h>
2 #include<sys/types.h>
3 #include<dirent.h>
4 int main(int argc ,char *argv[])
5 {
6 DIR *dir;
7 if(( dir = opendir(".")) == 0)
8 perror("open faile:");
9 else
10 printf("opendir ok\n");
11 if((closedir(dir)) < 0)
12 perror("close falie");
13 else
14 printf("close ok\n");
15
16 return 0;
17
18 }
NAME
opendir - open a directory
SYNOPSIS
头文件
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(const char *name);
DESCRIPTION
The opendir() function opens a directory stream corresponding to the
directory name, and returns a pointer to the directory stream. The
stream is positioned at the first entry in the directory.
RETURN VALUE
The opendir() function returns a pointer to the directory stream. On
error, NULL is returned, and errno is set appropriately.
ERRORS
EACCES Permission denied.
功能:opendir用来打开参数name制定的目录,并返回DIR*形态的目录流
返回值:成功返回目录流,失败返回NULL
man closedir:
NAME
closedir - close a directory
SYNOPSIS
#include <sys/types.h>
#include <dirent.h>
int closedir(DIR *dir);
DESCRIPTION
The closedir() function closes the directory stream associated with
dir. The directory stream descriptor dir is not available after this
call.
功能关闭一个 dir 所指的mulu
RETURN VALUE
The closedir() function returns 0 on success. On error, -1 is
returned, and errno is set appropriately.
返回值:成功返回0 错误返回-1
例子:
1 #include<stdio.h>
2 #include<sys/types.h>
3 #include<dirent.h>
4 int main(int argc ,char *argv[])
5 {
6 DIR *dir;
7 if(( dir = opendir(".")) == 0)
8 perror("open faile:");
9 else
10 printf("opendir ok\n");
11 if((closedir(dir)) < 0)
12 perror("close falie");
13 else
14 printf("close ok\n");
15
16 return 0;
17
18 }
相关文章推荐
- (二)和菜鸟一起学unix之文件目录 mkdir ,rmdir
- (二)和菜鸟一起学习unix之文件和目录 getcwd,chdir
- (二)和菜鸟一起学unix之文件和目录 stat
- Linux下目录文件的操作(opendir,readdir,closedir) 以及DIR,dirent,stat等结构体详解
- Linux C/C++ ----目录文件的操作(opendir,readdir,closedir)
- (一)和菜鸟一起学unix 之文件I/O:open ,close
- linux c学习笔记----目录文件的操作(opendir,readdir,closedir)
- linux 目录操作函数opendir readdir closedir,文件stat
- php读取目录文件函数is_dir(),opendir(),readdir(),closedir()
- linux c下目录文件的操作(opendir,readdir,closedir)
- opendir、readdir和closedir(PHP操作目录和文件)
- (一)和菜鸟一起学习unix之文件I/O:write read lseek
- (三) 一起学 Unix 环境高级编程 (APUE) 之 文件和目录
- linux C 遍历目录及其子目录 opendir -> readdir -> closedir http://blog.csdn.net/angle_birds/article/details/
- Unix:(提纲)关于目录和文件的操作
- 菜鸟学Linux命令:chmod命令 改变文件或目录存取模式
- UNIX环境高级编程-第4章- 文件和目录 - 二
- 关于Unix/Linux之Inode之我见----------Unix环境高级编程--目录、文件
- 《UNIX-Shell编程24学时教程》读书笔记Chap3,4 文件,目录操作
- Unix:基础知识文件和目录