C中的Globbing,如何排除文件

时间:2022-09-02 00:22:40

I've read http://linux.die.net/man/3/glob and it seems that glob will do disk access, even though I don't want it to.

我已经阅读了http://linux.die.net/man/3/glob,看来glob会进行磁盘访问,即使我不想这样做。

Is there a C glob function to compare a string with a glob pattern and tell me if it matches? i.e. no disk access.

是否有一个C glob函数来比较字符串与glob模式并告诉我它是否匹配?即没有磁盘访问。

If not, how can I use glob to exclude files when recursively (depth first) traversing a filesystem?

如果没有,我如何在递归(深度优先)遍历文件系统时使用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
}

1 个解决方案

#1


2  

Use the fnmatch function. It compares a filename/path against a given pattern.

使用fnmatch函数。它将文件名/路径与给定模式进行比较。

#1


2  

Use the fnmatch function. It compares a filename/path against a given pattern.

使用fnmatch函数。它将文件名/路径与给定模式进行比较。