LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fileutils.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_FILEUTILS_H
21 #define LIBREPCB_FILEUTILS_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../exceptions.h"
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 class FilePath;
36 
37 /*******************************************************************************
38  * Class FileUtils
39  ******************************************************************************/
40 
48 class FileUtils final {
49  Q_DECLARE_TR_FUNCTIONS(FileUtils)
50 
51 public:
52  // Constructors / Destructor
53  FileUtils() = delete;
54  FileUtils(const FileUtils& other) = delete;
55 
56  // Static methods
57 
67  static QByteArray readFile(const FilePath& filepath);
68 
80  static void writeFile(const FilePath& filepath, const QByteArray& content);
81 
91  static void copyFile(const FilePath& source, const FilePath& dest);
92 
102  static void copyDirRecursively(const FilePath& source, const FilePath& dest);
103 
113  static void move(const FilePath& source, const FilePath& dest);
114 
122  static void removeFile(const FilePath& file);
123 
131  static void removeDirRecursively(const FilePath& dir);
132 
138  static void makePath(const FilePath& path);
139 
149  static QList<FilePath> getFilesInDirectory(
150  const FilePath& dir, const QStringList& filters = QStringList());
151 
152  // Operator Overloadings
153  FileUtils& operator=(const FileUtils& rhs) = delete;
154 };
155 
156 } // namespace librepcb
157 
158 #endif // LIBREPCB_FILEUTILS_H
static void writeFile(const FilePath &filepath, const QByteArray &content)
Write the content of a QByteArray into a file.
Definition: fileutils.cpp:54
static void removeFile(const FilePath &file)
Remove a single file.
Definition: fileutils.cpp:137
static void makePath(const FilePath &path)
Create a directory with all parent directories.
Definition: fileutils.cpp:153
static void removeDirRecursively(const FilePath &dir)
Remove a directory recursively.
Definition: fileutils.cpp:145
FileUtils & operator=(const FileUtils &rhs)=delete
static void copyDirRecursively(const FilePath &source, const FilePath &dest)
Copy a directory recursively.
Definition: fileutils.cpp:95
static void copyFile(const FilePath &source, const FilePath &dest)
Copy a single file.
Definition: fileutils.cpp:77
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
static void move(const FilePath &source, const FilePath &dest)
Move/rename a file or directory.
Definition: fileutils.cpp:119
The FileUtils class provides some static methods to execute file operations.
Definition: fileutils.h:48
static QList< FilePath > getFilesInDirectory(const FilePath &dir, const QStringList &filters=QStringList())
Get all files in a given directory (optionally filtered by extension)
Definition: fileutils.cpp:161
static QByteArray readFile(const FilePath &filepath)
Read the content of a file into a QByteArray.
Definition: fileutils.cpp:38