Ha. I hope I didn't screw up this time.
#include <QCoreApplication> #include <QDir> #include <QDebug> // returns true if 'a' is a subdirectory of 'b' bool isSubdirectory(QDir a, QDir b) { while (!a.isRoot()) { if (a.absolutePath() == b.absolutePath()) return true; a.cdUp(); } return false; } int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QDir a("/Users/olegyadrov/one/two/three"); QDir b("/Users/olegyadrov/one/two"); QDir c("/Users/olegyadrov/one/four"); qDebug() << isSubdirectory(a, b); qDebug() << isSubdirectory(a, c); return app.exec(); } On Jul 11, 2018, at 10:59 AM, Thiago Macieira <thiago.macie...@intel.com<mailto:thiago.macie...@intel.com>> wrote: On Wednesday, 11 July 2018 07:44:46 PDT Oleg Yadrov wrote: qDebug() << a.absolutePath().startsWith(b.absolutePath()); qDebug() << a.absolutePath().startsWith(c.absolutePath()); Except that this has a bug (which we had in Qt too): these two directories are considered to be parent-child, when they're not C:\One\TwoAndTwenty C:\One\Two And since we're talking about Windows, you also need to use case-insensitive comparison. -- Thiago Macieira - thiago.macieira (AT) intel.com<http://intel.com> Software Architect - Intel Open Source Technology Center _______________________________________________ Interest mailing list Interest@qt-project.org<mailto:Interest@qt-project.org> http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest