Since QDir & QDir::EntryList has some serious trouble with (MacOS) app-bundles, I ended up implementing the QDirIterator solution @Chris-Kawa suggested:
void copyAndReplaceFolderContents(const QString &fromDir, const QString &toDir, bool copyAndRemove = false) { QDirIterator it(fromDir, QDirIterator::Subdirectories); QDir dir(fromDir); const int absSourcePathLength = dir.absoluteFilePath(fromDir).length(); while (it.hasNext()){ it.next(); const auto fileInfo = it.fileInfo(); if(!fileInfo.isHidden()) { //filters dot and dotdot const QString subPathStructure = fileInfo.absoluteFilePath().mid(absSourcePathLength); const QString constructedAbsolutePath = toDir + subPathStructure; if(fileInfo.isDir()){ //Create directory in target folder dir.mkpath(constructedAbsolutePath); } else if(fileInfo.isFile()) { //Copy File to target directory //Remove file at target location, if it exists, or QFile::copy will fail QFile::remove(constructedAbsolutePath); QFile::copy(fileInfo.absoluteFilePath(), constructedAbsolutePath); } } } if(copyAndRemove) dir.removeRecursively(); }Language Bindings
You're using Qt with other languages than C++, eh? Post here!
850
Topics
3.3k
Posts
-
Copy folder qt c ++
Solved -
-
-
-
PyQt doesn't understand &
Solved -
-
-
Troubles using pyuic5
Solved -
-
-
-
-
-
Unattended install
Moved Unsolved -
QT Designer can't detect python
Unsolved -
-
PyQt / Pyside2 commitment to Mac OS?
Unsolved -
-
-
Porting from Embarcadero C++
Unsolved