全球搜索目录也 returns 文件
Glob searching directories also returns files
为什么将 glob
函数与路径 /home/user/*/
return 两个目录 和 文件一起使用。我希望由于路径以 /
结尾,所以只有目录应该 returned,但它也是 returning 文件。
我是运行以下代码:
vector<string> glob(const std::string& path)
{
glob_t glob_result;
glob(path.c_str(),GLOB_TILDE,NULL,&glob_result);
vector<string> ret;
for(unsigned int i=0;i<glob_result.gl_pathc;++i){
ret.push_back(string(glob_result.gl_pathv[i]));
}
globfree(&glob_result);
return ret;
}
函数的输入为 /home/user/*/
,输出为 /home/user/a.txt
、/home/user/b.txt
和 /home/user/nested_folder
为什么 return 同时处理文件和目录而不是只处理目录。
这是一个旧的 glibc 错误,已在 glibc 2.19 中修复:
为什么将 glob
函数与路径 /home/user/*/
return 两个目录 和 文件一起使用。我希望由于路径以 /
结尾,所以只有目录应该 returned,但它也是 returning 文件。
我是运行以下代码:
vector<string> glob(const std::string& path)
{
glob_t glob_result;
glob(path.c_str(),GLOB_TILDE,NULL,&glob_result);
vector<string> ret;
for(unsigned int i=0;i<glob_result.gl_pathc;++i){
ret.push_back(string(glob_result.gl_pathv[i]));
}
globfree(&glob_result);
return ret;
}
函数的输入为 /home/user/*/
,输出为 /home/user/a.txt
、/home/user/b.txt
和 /home/user/nested_folder
为什么 return 同时处理文件和目录而不是只处理目录。
这是一个旧的 glibc 错误,已在 glibc 2.19 中修复: