| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qfileutil_p.h" |
| 5 | #include <QtCore/qfile.h> |
| 6 | #include <QtCore/qdiriterator.h> |
| 7 | #include <QtCore/qfileinfo.h> |
| 8 | #include <QtCore/qstring.h> |
| 9 | |
| 10 | QT_BEGIN_NAMESPACE |
| 11 | |
| 12 | bool copyAllFiles(const QDir &source, const QDir &dest) |
| 13 | { |
| 14 | using namespace Qt::Literals; |
| 15 | |
| 16 | if (!source.exists() || !dest.exists()) |
| 17 | return false; |
| 18 | |
| 19 | QDirIterator it(source); |
| 20 | bool success = true; |
| 21 | while (it.hasNext()) { |
| 22 | QFileInfo file{ it.next() }; |
| 23 | if (file.isFile()) { |
| 24 | const QString destination = dest.absolutePath() + u"/"_s+ file.fileName(); |
| 25 | |
| 26 | if (QFile::exists(fileName: destination)) |
| 27 | if (!QFile::remove(fileName: destination)) |
| 28 | success = false; |
| 29 | |
| 30 | if (!QFile::copy(fileName: file.absoluteFilePath(), newName: destination)) |
| 31 | success = false; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | return success; |
| 36 | } |
| 37 | |
| 38 | QT_END_NAMESPACE |
| 39 |
