#include <stdio.h> #include <dirent.h> int main(void) { struct dirent *de; // Pointer for directory entry // opendir() returns a pointer of DIR type. DIR *dr = opendir("."); if (dr == NULL) // opendir returns NULL if couldn't open directory { printf("Could not open current directory" ); return 0; } // for readdir() while ((de = readdir(dr)) != NULL) printf("%s\n", de->d_name); closedir(dr); return 0; } |
chevron_right
filter_none
Output:
All files and subdirectories
of current directory
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- C program to compare two files and report mismatches
- C Program to merge contents of two files into a third file
- What’s difference between header files "stdio.h" and "stdlib.h" ?
- Linking Files having same variables with different data types in C
- Header files in C/C++ with Examples
- C program to detect tokens in a C program
- C program to print a string without any quote (singe or double) in the program
- Hello World Program : First program while learning Programming
- Lex program to take input from file and remove multiple spaces, lines and tabs
- Forward List in C++ | Set 1 (Introduction and Important Functions)
- Write a program that produces different results in C and C++
- C program to demonstrate fork() and pipe()
- Write a C program to print "GfG" repeatedly without using loop, recursion and any control structure?
- How to compile 32-bit program on 64-bit gcc in C and C++
- Program to print hollow pyramid and diamond pattern
- C Program for Lower Case to Uppercase and vice-versa in a file
- C Program to display hostname and IP address
- How to execute zombie and orphan process in a single program?
- C Program to Compute Quotient and Remainder
- C/C++ program to find the size of int, float, double and char

