Globbing 在 C 中,如何排除文件

Globbing in C, how to exclude files

我读过 http://linux.die.net/man/3/glob 似乎 glob 会进行磁盘访问,尽管我不希望它这样做。

是否有 C glob 函数可以将字符串与 glob 模式进行比较并告诉我它是否匹配?即没有磁盘访问。

如果不是,我如何在递归(深度优先)遍历文件系统时使用 glob 排除 文件?

while((entry = readdir(dp))) {
    // need to continue to next iteration of loop, here, if entry->d_name matches glob pattern

    // do stuff and recurse
}

使用fnmatch函数。它将 filename/path 与给定模式进行比较。