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 
45 class FileUtils final {
46  Q_DECLARE_TR_FUNCTIONS(FileUtils)
47 
48 public:
49  // Constructors / Destructor
50  FileUtils() = delete;
51  FileUtils(const FileUtils& other) = delete;
52 
53  // Static methods
54 
64  static QByteArray readFile(const FilePath& filepath);
65 
77  static void writeFile(const FilePath& filepath, const QByteArray& content);
78 
88  static void copyFile(const FilePath& source, const FilePath& dest);
89 
99  static void copyDirRecursively(const FilePath& source, const FilePath& dest);
100 
110  static void move(const FilePath& source, const FilePath& dest);
111 
119  static void removeFile(const FilePath& file);
120 
128  static void removeDirRecursively(const FilePath& dir);
129 
135  static void makePath(const FilePath& path);
136 
146  static QList<FilePath> getFilesInDirectory(
147  const FilePath& dir, const QStringList& filters = QStringList());
148 
149  // Operator Overloadings
150  FileUtils& operator=(const FileUtils& rhs) = delete;
151 };
152 
153 } // namespace librepcb
154 
155 #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:127
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:45
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