Author Topic: Turbo C Program to list all files in a folder  (Read 2366 times)


  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Turbo C Program to list all files in a folder
« on: February 08, 2012, 01:47:24 pm »
I have given here Turbo C program to list all files in a folder:

//Source Code Listing

#include <dirent.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>

int Display_All_Files(char *searchstring)
   DIR *directory_list;
   int count = 0;
   struct dirent *dentry;
   char buf[128];
   directory_list = opendir (searchstring);
   if (directory_list != NULL) {
      while ((dentry = readdir (directory_list)) != NULL) {
	 strcat(buf, dentry->d_name);
	 if(opendir(buf) == NULL)
		 printf ("File: %s\n", dentry->d_name);
      closedir (directory_list);
   } else {
      printf("could not open directory");
   return count;

void main()
   char searchstring[128] = "c:\\";
   int count = 0;
   count = Display_All_Files(searchstring);
   printf("\n%d files found\n\n", count);

The output would the list of files in C:\ directory. At the end it will display how many files are there in the current directory.


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1