Pages

Thursday, March 29, 2018

List Files in Directory


Following C Program will display the List of Files present in current directory. This C program is stored in D:\\CProgramPracticals\ directory; hence it will display all files stored in this directory.

Program to Display List of Files in Current Directory

#include <stdio.h>
#include <dirent.h> 
int main()
{
    DIR *my_dir;
    struct dirent *temp_dir;
    my_dir = opendir(".");
    if (my_dir)
    {
        while ((temp_dir = readdir(my_dir)) != NULL)
        {
            printf("%s\n", temp_dir->d_name);            
        }
        closedir(my_dir);
    }
    return 0;
}



Output of Program

.
..
Armstrong-number.c
bell-using-ascii-7.c
bitcoin_profitloss.c
bitcoin_profitloss.exe
blink.c
cprogrampracticals.h
digitsToWords.c
digitsToWords.exe
EMICalulator.c
EMICalulator.exe
leapYear.c
leapYear.exe
LifeInsurancePremiumCalculator.c
LifeInsurancePremiumCalculator.exe
piano.c
ReadIPAddress.c
ReadIPAddress.exe
StockBroker.c
StockClientBill.c
StockClientBill.exe
swap-variable.c
SystemDateTime.c


No comments:

Post a Comment