Wednesday, March 16, 2016

c program to print the names of all the files in current directory

#include<stdio.h>
#include<dirent.h>
void main()
{
  DIR *d;
 struct dirent *dir;
 d=opendir("."); //pointing to current directory
 if(d)
  {
   while((dir=readdir(d))!=NULL)
   {
    printf("\n%s",dir->d_name);
   }
   closedir(d);
  }
 }

output
abc.txt
hello.txt
program1.c
newhello.txt

No comments:

Post a Comment