LibrePCB Developers Documentation
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_CORE_FILEUTILS_H
21 #define LIBREPCB_CORE_FILEUTILS_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include <QtCore>
27 
28 /*******************************************************************************
29  * Namespace / Forward Declarations
30  ******************************************************************************/
31 namespace librepcb {
32 
33 class FilePath;
34 
35 /*******************************************************************************
36  * Class FileUtils
37  ******************************************************************************/
38 
43 class FileUtils final {
44  Q_DECLARE_TR_FUNCTIONS(FileUtils)
45 
46 public:
47  // Constructors / Destructor
48  FileUtils() = delete;
49  FileUtils(const FileUtils& other) = delete;
50 
51  // Static methods
52 
62  static QByteArray readFile(const FilePath& filepath);
63 
75  static void writeFile(const FilePath& filepath, const QByteArray& content);
76 
86  static void copyFile(const FilePath& source, const FilePath& dest);
87 
97  static void copyDirRecursively(const FilePath& source, const FilePath& dest);
98 
108  static void move(const FilePath& source, const FilePath& dest);
109 
117  static void removeFile(const FilePath& file);
118 
126  static void removeDirRecursively(const FilePath& dir);
127 
133  static void makePath(const FilePath& path);
134 
146  static QList<FilePath> getFilesInDirectory(
147  const FilePath& dir, const QStringList& filters = QStringList(),
148  bool recursive = false, bool skipHiddenFiles = false);
149 
158  static QList<FilePath> findDirectories(const FilePath& rootDir);
159 
160  // Operator Overloadings
161  FileUtils& operator=(const FileUtils& rhs) = delete;
162 };
163 
164 } // namespace librepcb
165 
166 #endif
static void writeFile(const FilePath &filepath, const QByteArray &content)
Write the content of a QByteArray into a file.
Definition: fileutils.cpp:55
static QList< FilePath > getFilesInDirectory(const FilePath &dir, const QStringList &filters=QStringList(), bool recursive=false, bool skipHiddenFiles=false)
Get all files in a given directory (optionally filtered by extension)
Definition: fileutils.cpp:164
static void removeFile(const FilePath &file)
Remove a single file.
Definition: fileutils.cpp:140
Definition: occmodel.cpp:76
static void makePath(const FilePath &path)
Create a directory with all parent directories.
Definition: fileutils.cpp:156
static void removeDirRecursively(const FilePath &dir)
Remove a directory recursively.
Definition: fileutils.cpp:148
FileUtils & operator=(const FileUtils &rhs)=delete
static void copyDirRecursively(const FilePath &source, const FilePath &dest)
Copy a directory recursively.
Definition: fileutils.cpp:96
static QList< FilePath > findDirectories(const FilePath &rootDir)
Get all directories within a given directory.
Definition: fileutils.cpp:190
static void copyFile(const FilePath &source, const FilePath &dest)
Copy a single file.
Definition: fileutils.cpp:78
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:120
The FileUtils class provides some static methods to execute file operations.
Definition: fileutils.h:43
static QByteArray readFile(const FilePath &filepath)
Read the content of a file into a QByteArray.
Definition: fileutils.cpp:39