structdirent { ino_t d_ino; /* Inode number */ off_t d_off; /* Not an offset; see below */ unsignedshort d_reclen; /* Length of this record */ unsignedchar d_type; /* Type of file; not supported by all filesystem types */ char d_name[256]; /* Null-terminated filename */ };
d_type:
DT_BLK This is a block device. DT_CHR This is a character device. DT_DIR This is a directory. DT_FIFO This is a named pipe (FIFO). DT_LNK This is a symbolic link. DT_REG This is a regular file. DT_SOCK This is a UNIX domain socket. DT_UNKNOWN The file type could not be determined.
打开目录
#include<sys/types.h> #include<dirent.h> DIR *opendir(constchar *name); DIR *fdopendir(int fd);
If path does not contain a slash, dirname() returns the string “.”
while basename() returns a copy of path. If path is the string “/”, then
both dirname() and basename() return the string “/”. If path is a null
pointer or points to an empty string, then both dirname() and basename()
return the string “.”.