Tuesday, September 28, 2010

Directory finding



/*
* Finding the files in the particular files.
*
*/

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
# include <string.h>


int isFileExist(char* dirName, char* fileName)
{
DIR *dp;
struct dirent *ep;
dp = opendir ("./");

if (dp != NULL)
{
while(ep = readdir(dp))
{
puts (ep->d_name);
if(strcmp(fileName, ep->d_name) ==0)
return 0;
}
(void) closedir (dp);
}
else
perror ("Couldn't open the directory");
return -1;

}

int main (void)
{

printf("is Exist %d",isFileExist("./","Printf.c"));
//perror("flfllfglllglf");
/* DIR *dp;
struct dirent *ep;
dp = opendir ("./");

if (dp != NULL)
{
while(ep = readdir(dp))
puts (ep->d_name);

(void) closedir (dp);
}
else
perror ("Couldn't open the directory"); */

return 0;
}

No comments:

Post a Comment