Reading Directory with C/C++

//Read A Director
//Tested in Linux and SOLARIS

#include " stdio.h"
#include "dirent.h"
#include " errno.h"
int main()
{
printf("opening Directory 1\n");
DIR *pdir;
struct dirent *pfile;
pdir = opendir("ren");
if(NULL == pdir)
{
printf("Error Opening Directory\n");
exit(0);
}
while(pfile = readdir(pdir))
{
if(0 == (strcmp(pfile->d_name,".")))
continue;
else if(0 == (strcmp(pfile->d_name,"..")))
continue;
else
printf("the file names=%s\n",pfile->d_name);
}
return 0;

0 comments: