Sayonara Player
FileUtils.h
1 /* FileUtils.h */
2 
3 /* Copyright (C) 2011-2017 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef FileUtils_H
22 #define FileUtils_H
23 
24 #include <cstdint>
25 
26 class QStringList;
27 class QString;
28 class QByteArray;
29 
30 namespace Util
31 {
36  namespace File
37  {
43  QString clean_filename(const QString& filename);
44 
50  QString calc_file_extension(const QString& filename);
51 
52  QByteArray calc_md5_sum(const QString& filename);
53 
59  void remove_files_in_directory(const QString& dir_name, const QStringList& filters);
60  void remove_files_in_directory(const QString& dir_name);
61 
66  void delete_files(const QStringList& files);
67 
73  QString get_parent_directory(const QString& path);
74 
80  QString get_filename_of_path(const QString& path);
81 
88  void split_filename(const QString& src, QString& dir, QString& filename);
89 
90  QStringList split_directories(const QString& path);
91 
97  QString get_file_extension(const QString& filename);
98 
104  QStringList get_parent_directories(const QStringList& list);
105 
111  QString get_absolute_filename(const QString& filename);
112 
117  bool create_directories(const QString& path);
118 
119  bool create_symlink(const QString& source, const QString& target);
120 
121 
127  QString calc_filesize_str(uint64_t filesize);
128 
129 
135  bool is_absolute(const QString& filename);
136 
137 
144  bool write_file(const QByteArray& raw_data, const QString& filename);
145 
152  bool read_file_into_str(const QString& filename, QString& content);
153 
160  bool read_file_into_byte_arr(const QString& filename, QByteArray& content);
161 
167  bool check_file(const QString& filepath);
168 
169  QString get_common_directory(const QStringList& paths);
170  QString get_common_directory(QString dir1, QString dir2);
171 
172  bool create_dir(const QString& dir_name);
173  bool copy_dir(const QString& src_dir, const QString& target_dir);
174  QString move_dir(const QString& src_dir, const QString& target_dir);
175  bool rename_dir(const QString& src_dir, const QString& new_name);
176  bool can_copy_dir(const QString& src_dir, const QString& target_dir);
177 
178  bool move_file(const QString& file, const QString& dir);
179  bool copy_file(const QString& file, const QString& dir);
180  bool move_files(const QStringList& files, const QString& dir);
181  bool rename_file(const QString& old_name, const QString& new_name);
182  bool copy_files(const QStringList& files, const QString& dir);
183 
184 
185  // Everything clear
186  bool is_url(const QString& str);
187  bool is_www(const QString& str);
188  bool is_file(const QString& filename);
189  bool is_dir(const QString& filename);
190  bool is_soundfile(const QString& filename);
191  bool is_playlistfile(const QString& filename);
192  bool is_imagefile(const QString& filename);
193  }
194 }
195 
196 #endif // FileUtils_H
void remove_files_in_directory(const QString &dir_name, const QStringList &filters)
Remove all files from directory.
QString clean_filename(const QString &filename)
formatter for filepaths. Removes double separators and replaces them with os specific separators...
QStringList get_parent_directories(const QStringList &list)
extract parent folder of a file list (see also get_parent_directory(const QString& path) ...
void delete_files(const QStringList &files)
Remove all given files (also directories can be specified)
QString get_filename_of_path(const QString &path)
extract pure filename from a complete file path
bool is_absolute(const QString &filename)
Tell whether filename is absolute.
Helper functions.
Definition: FileUtils.h:30
bool read_file_into_byte_arr(const QString &filename, QByteArray &content)
read a complete file into a byte array
void split_filename(const QString &src, QString &dir, QString &filename)
split filename into the dir and filename
bool check_file(const QString &filepath)
Check, if file is valid. Web URLs are always valid.
QString calc_file_extension(const QString &filename)
calc_file_extension
QString calc_filesize_str(uint64_t filesize)
convert filesize to string
bool read_file_into_str(const QString &filename, QString &content)
read a complete file into a string
QString get_parent_directory(const QString &path)
get parent directory of a filepath
bool write_file(const QByteArray &raw_data, const QString &filename)
Write raw data to file.
QString get_file_extension(const QString &filename)
get file extension
QString get_absolute_filename(const QString &filename)
get absolute filename of file
bool create_directories(const QString &path)
create all directories necessary to access path