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

kathir

  • 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:

Code:
//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) {
	 strcpy(buf,searchstring);
	 strcat(buf, dentry->d_name);
	 if(opendir(buf) == NULL)
	 {
		 printf ("File: %s\n", dentry->d_name);
		 count++;
	 }
      }
      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);
   getch();
}

/***
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.
***/



ClintonEnupt

  • Sr. Member
  • ****
  • Posts: 341
    • тинедол Полезные свойства и ...
Фабрика Инте
« Reply #1 on: April 08, 2017, 06:23:04 am »
Гостиная Версаль
www.imp-mebeli.ru
----------

ClintonEnupt

  • Sr. Member
  • ****
  • Posts: 341
    • тинедол Полезные свойства и ...
Фабрика Инте
« Reply #2 on: April 08, 2017, 06:23:33 am »
Гостиная Версаль
www.imp-mebeli.ru
----------

ClintonEnupt

  • Sr. Member
  • ****
  • Posts: 341
    • тинедол Полезные свойства и ...
Фабрика Инте
« Reply #3 on: April 08, 2017, 06:25:06 am »
Гостиная Версаль
www.imp-mebeli.ru
----------

ClintonEnupt

  • Sr. Member
  • ****
  • Posts: 341
    • тинедол Полезные свойства и ...
Фабрика Инте
« Reply #4 on: April 08, 2017, 06:30:58 am »
Гостиная Версаль
www.imp-mebeli.ru
----------

 


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