1. chdir modify the working directory of the current process (Man 2 chdir view)
int chdir (const char *path); //path Path
int fchdir (int fd); //fd File descriptor
Return value: 0 successfully returned, failure returned-1.
2. GETCWD get the working directory of the current process
Char *getcwd (char *buf, size_t size); //buf The outgoing parameter, size is the length of the BUF,
Char *getwd (char *buf);
Char *get_current_dir_name (void);
Return value: The path was successfully returned and Null was returned by failure.
3. mkdir Create a directory
int mkdir (const char *pathname, mode_t mode); //pathname directory name, mode permission
Return value: 0 successfully returned, failure returned-1.
Attached: The created command needs to have executable permissions, otherwise it cannot enter the directory, so the created directory does not make any sense.
4. RmDir Delete an empty directory
int rmdir (const char *pathname); //pathname Directory Name
Return value: 0 successfully returned, failure returned-1.
5. Opendir Open a directory (man 3 opendir view)
DIR *opendir (const char *name); //directory Name
DIR *fdopendir (int fd); //File descriptor
Return value: The successful return of the directory pointer (similar to the file structure), and the failure to return null.
6. Readdir Read directory (man 3 Readdir view)
struct Dirent *readdir (DIR *dirp); //dirp is a dir struct pointer, typically obtained by the return value of Opendir
Return value: The struct pointer that successfully returned the structure dirent, failed to return null.
int Readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result); //entry outgoing parameter, next directory record; result outgoing parameter, current read result
Return value: Successful return 0,*result equals null means read out;
Attached: Below is a description of struct dirent struct:
struct Dirent {
ino_t D_ino; /* Inode number inode No. */
off_t D_off; /* Offset to the next Dirent directory at the beginning to the point of entry */
unsigned short d_reclen; /* Length of this record d_name, excluding the null character */
unsigned char d_type; /* type of file; Not supported by all file system types file type */
Char d_name[256]; /* FileName File name */
};
7. Closedir Close the Directory
int Closedir (DIR *dirp); //Close the directory, DIRP by the return value of Opendir
Return value: 0 successfully returned, failure returned-1.
8. Seekdir,telldir,scandir and more, see the Man manual for more specific functions and how to use them.
Common system function descriptions for Linux directory operations