Like a file, you can open a directory to read its database of files as managed by the operating system. The opendir() function opens a directory on the path provided. A DIR variable, similar to a FILE variable for opening a file, is returned by the opendir() function. The readdir() function returns a dirent structure containing information about entries, or files, in the directory. When you're done reading the directory, use the closedir() function to close it.
- [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 …
- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
1. Arrays and Structures
2. Characters and Strings
4. Files and the Operating System
5. The Interesting and Extraordinary
Next steps1m 52s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.