在给定目录中搜索指定文件

int find_file_in_dir(const char *path, const char *file) {
    struct dirent *entry;
    int ret=1;
    DIR *dir;

    dir = opendir(path);
    errno = 0;
    while((entry = readdir(dir)) != NULL) {
        if(strcmp(entry->d_name, file) == 0) {
            ret = 0;
            break;
        }
    }

    if(errno && !entry)
        perror("readdir");
    closedir(dir);
    return ret;
}
posted @ 2020-08-17 21:35  东宫得臣  阅读(141)  评论(0编辑  收藏  举报