Qt 6.11 is out! See what's new in the release
blog
Check how deep folder is compared to other folder
-
Hello,
Lets say I have base folder /test
I wonder if there is something standard in Qt that would let me know how deep I am from base folder.
I.e. My other folder is /test/sample/end and comparing to base folder it would return 2 then /test/sample would return 1 and /test would return 0. -
Try:
int countDepth(QDir directory){ int result; for(result=0;directory.cdUp();++result){} return result; }@VRonin I have tried it and added check to see if folder includes base folder
QDir basePath("/home/something/test"); QDir t("/home/something/test/sample/end"); QDirIterator it(basePath, QDirIterator::Subdirectories); bool isBase = false; while (it.hasNext()) { if (it.next() == t.path()) { isBase = true; break; } } int i = 0; if (isBase) { while (basePath.path() != t.path()) { t.cdUp(); i++; } } else { i = - 1; } qDebug() << i;