Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qfileutil.cpp
Go to the documentation of this file.
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
11
12bool 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, QDirIterator::Subdirectories);
20 bool success = true;
21 while (it.hasNext()) {
22 QFileInfo file{ it.next() };
23 const QString relativePath = source.relativeFilePath(file.absoluteFilePath());
24 const QString destination = dest.absolutePath() + u"/"_s + relativePath;
25
26 if (file.isFile()) {
27 if (QFile::exists(destination))
28 if (!QFile::remove(destination))
29 success = false;
30
31 if (!QFile::copy(file.absoluteFilePath(), destination))
32 success = false;
33
34 } else if (file.isDir()) {
35 if (!QDir(destination).exists())
36 if (!dest.mkpath(relativePath))
37 success = false;
38 }
39 }
40
41 return success;
42}
43
44QT_END_NAMESPACE
QT_BEGIN_NAMESPACE bool copyAllFiles(const QDir &source, const QDir &dest)
Definition qfileutil.cpp:12