我想编写一个程序,输出一个文件夹内目录的目录列表,例如,我得到了以下代码:
#include <stdio.h>
#include <dirent.h>
int main(void)
{
struct dirent *de; // Pointer for directory entry
// opendir() returns a pointer of DIR type.
DIR *dr = opendir(".");
if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory" );
return 0;
}
while ((de = readdir(dr)) != NULL)
printf("%s\n", de->d_name);
closedir(dr);
return 0;
}
,我有一个名为“ Test”的文件夹,输出为-> test, 但我希望它显示文件夹中的文件夹,例如: “测试/insideFolder/anotherInsideFolder/file.c” 可以做到吗?