C Programming
Computer Programming

C file handling program to print the list of files and subdirectories of the current directory



Write C file handling program to print the list of files and subdirectories of the current directory

\* C file handling program to print the list of files and subdirectories of the current directory *\

# include < stdio.h >
# include < dirent.h >
int   main( )
{

DIR* dObj ;
struct dirent* dir ;
dObj = opendir(".") ;
printf("\nList of files and sub directories: \n" ) ;
if (dObj != NULL)
{
      while ((dir = readdir(dObj)) != NULL )
      {
            printf("%s\n", dir->d_name ) ;
      }
      closedir( dObj ) ;
}
return (0) ;

}

Output of Program :

Output of C file handling program to print the list of files and subdirectories of the current directory