List All Contents of Directory C Program

C Program To List Contents of Directory and Sub Directories

Learn How To List Names of all Files, Sub Directories and Contents of Directory in C Programming Language. Get the list of all files and sub directories in a directory using dirent.h header file.

This is a simple directory lister c program that enlists the names of all the files in a directory. We have used opendir() method that passes the directory name to the pointer which is then used by readdir() method to return the names of the files and sub directories in that directory.

About Dirent.h

The dirent.h header file is used to work with the directories in C programming. DIR is a type representing a directory stream. The struct dirent structure is a structure type used to return information about directory entries.

Must Read: How To Create User Defined Header Files in C Programming

C Program To List Contents of Directory using dirent.h


C Program To List Contents of Directory using dirent.h

If you have any compilation error or doubts in this C program to list all the sub directories and folders in a given directory, let us know about it in the comment section below. Find more about dirent.h here.

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

3 thoughts on “List All Contents of Directory C Program

  • October 19, 2016 at 1:20 am

    Does this program also lists the hidden files and sub directories?

    • October 20, 2016 at 7:52 am

      Yes. This Directory Lister C Program does enlists the Hidden files of my directory.

  • October 19, 2016 at 12:01 pm

    There are so many functions and header files in C library that I have not even heard of. This is something unique. Thanks. Keep updating us with the same.


Join The Discussion