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 - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
Reading from a file3m 25s
-
(Locked)
Writing to a file3m 24s
-
(Locked)
Working with raw data2m 53s
-
(Locked)
Using random file access2m 47s
-
(Locked)
Manipulating files2m 57s
-
(Locked)
Exploring the path2m 8s
-
(Locked)
Reading a directory2m 53s
-
(Locked)
Getting file information2m 46s
-
(Locked)
Using command line arguments2m 44s
-
(Locked)
Calling the operating system2m 46s
-
(Locked)
Challenge: Read and store filenames1m 6s
-
(Locked)
Solution: Read and store filenames2m 52s
-
-
-