From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Reading a directory

Reading a directory

- [Narrator] A directory is a special type of file, like a database. Its contents reference files on the storage media as managed by the operating system. Just as you can open a file, you can open a directory to examine its contents and obtain information about the files stored there. To open a directory, you use the opendir function. This function is prototyped in the dirent.h header file. Its argument is a string representing the path to a directory to open. The value returned is a dir pointer, which is like the file pointer used to reference open files. Once a directory is opened, you use the read dir function to read its contents. This function is prototyped in the dirent header file. Its argument is the directory handle. The dir address returned from the open dir function. The read dir function returns the address of a dirent structure, which contains information about a file in the directory's database. Members of the dirent structure can be examined to describe files stored in…

Contents