From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Reading a directory

Reading a directory - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Reading a directory

- [Instructor] A directory is a special type of file. It's like a database referencing other files on the storage media as managed by the operating system. Just as you can open a file, you can also open a directory to examine its list of files, its database. The function to open a directory is opendir. It's prototyped in the dirent header file. The only argument is a string, representing a path to the directory to open. The value returned is a DIR pointer. This is similar to the file pointer returned from the fopen function. And like opening a file, when you're done with a directory you use the closedir function to close it. To read files from an open directory, you use the readdir function. Like the opendir function, its prototyped in the dirent header file. It's argument is the directory handle the DIR address returned from the opendir function. This function returns the address of a directory entry structure, dirent. Your code can examine the members of the dirent structure to…

Contents