gpt4 book ai didi

c++ - Linux 目录 : Getting a list of all folders inside a directory

转载 作者:太空宇宙 更新时间:2023-11-04 10:48:15 24 4
gpt4 key购买 nike

以下是我用来获取当前文件夹中所有文件夹列表的代码片段。我想要红色的“。”和列表中的“..”文件夹,但不知何故不能。

const char* root_dir_c  = root_dir.c_str();
DIR *pdir = opendir(root_dir_c);
struct dirent *entry = readdir(pdir);

while (entry != NULL){
if ((entry->d_type == DT_DIR) && (entry->d_name != ".") && (entry->d_name != "..")){
// DO STUFF
}
entry = readdir(pdir);
}

你能帮忙吗?

最佳答案

entry->d_name 是一个 char 数组,它不能与 != 一起使用,您需要使用 strcmp 或类似的。

关于c++ - Linux 目录 : Getting a list of all folders inside a directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32145890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com