linux应用查找某一目录下文件存在与否小程序

来源:互联网 发布:梦龙网络计划软件win7 编辑:程序博客网 时间:2024/05/08 00:20

判断某一目录下的文件是否存在,可直接用程序中。

int  CheckCfg(char *pFileName, char *pFilePath)

{
char  dirBuf[256] = {0};
DIR * dir;
struct dirent * ptr;
strcpy(dirBuf,pFilePath);
dir = opendir(dirBuf);
while((ptr = readdir(dir)) != NULL)
{
if(strcmp(ptr->d_name,pFileName) == 0)
{
return 1;
}
}
return 0;
}
1 0