I'd do:
int countFiles
(const QString &path,
bool countDirs
=false){ if(!finfo.exists() || !finfo.isDir())
return 0;
int res = 0;
QStringList slist
= finfo.
absoluteDir().
entryList(QDir::Dirs|QDir
::NoSymLinks|QDir
::NoDotAndDotDot);
if(childInfo.isDir()){
if(countDirs)
res++;
res+=countFiles(path, countDirs);
} else
res++;
}
return res;
}
int countFiles(const QString &path, bool countDirs=false){
QFileInfo finfo(path);
if(!finfo.exists() || !finfo.isDir())
return 0;
int res = 0;
QStringList slist = finfo.absoluteDir().entryList(QDir::Dirs|QDir::NoSymLinks|QDir::NoDotAndDotDot);
foreach(QString path, slist){
QFileInfo childinfo(path);
if(childInfo.isDir()){
if(countDirs)
res++;
res+=countFiles(path, countDirs);
} else
res++;
}
return res;
}
To copy to clipboard, switch view to plain text mode
Bookmarks