我有一个根文件夹包括获取列表文件夹和文件列表中的根文件夹通过dirent.h在C++
+ Test1(folder) > Test2(folder)>Test3(folder)>file1,file2....(file)
+ Test5(folder) > Test6(folder)>file1,file2....(file)
如何获得列表文件的输入是C盘根目录++。如果列表文件(文件1,文件2 ....)是子文件夹根文件夹(根文件夹>文件1,文件2 ...),我可以成功获取列表文件。但在我的情况下,要获取列表文件,我必须扫描许多父文件夹。如何在我的情况下获取列表文件?这是我的代码,如果没有父文件夹
DIR *dirStr = NULL;
dirStr = opendir(rootpath)
dirent *nextFile = NULL;
while ((nextFile = readdir(dirStr))!=NULL)
{
// Avoid hidden files
//Scan all file an dictionary
if (nextFile->d_name[0] != '.')
{
cout<<nextFile->d_name<<endl;
}
}
从这里了解:[目录递归扫描程序(http://www.johnloomis.org/ece537/notes/Files/ Examples/printdir.html) – 2013-02-25 16:09:28
在POSIX平台上,'fts(3)'可能是一个选项。 – 2013-02-25 16:09:29