我有一個根文件夾包括獲取列表文件夾和文件列表中的根文件夾通過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