Easy3D 2.5.3
file_system.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_UTIL_FILE_SYSTEM_H
28#define EASY3D_UTIL_FILE_SYSTEM_H
29
30#include <string>
31#include <vector>
32#include <fstream>
33
34
35namespace easy3d {
36
46 namespace file_system {
47
53 bool is_file(const std::string& path);
54
60 bool is_directory(const std::string& path);
61
67 bool create_directory(const std::string& path);
68
75 bool delete_file(const std::string& path);
76
83 bool delete_directory(const std::string& path);
84
91 bool delete_contents(const std::string& path);
92
101 void get_directory_entries(const std::string& path, std::vector<std::string>& entries, bool recursive);
102
111 void get_files(const std::string& path, std::vector<std::string>& files, bool recursive);
112
121 void get_sub_directories(const std::string& path, std::vector<std::string>& subs, bool recursive);
122
128
134 bool set_current_working_directory(const std::string& path);
135
140 std::string home_directory();
141
146 std::string executable();
147
152 std::string executable_directory();
153
160 bool rename_file(const std::string& old_name, const std::string& new_name);
161
167 time_t time_stamp(const std::string& path);
168
174 std::string time_string(const std::string& path);
175
181 std::ifstream::pos_type file_size(const std::string& path);
182
189 std::string parent_directory(const std::string& path) ;
190
197 std::string extension(const std::string& path, bool lower = true) ;
198
204 std::string simple_name(const std::string& path) ;
205
212 std::string base_name(const std::string& path) ;
213
220 std::string name_less_extension(const std::string& path);
221
228 std::string name_less_all_extensions(const std::string& path);
229
237 std::string replace_extension(std::string const& path, const std::string& ext);
238
244 std::string path_root(const std::string& path);
245
252 bool is_absolute_path(const std::string& path);
253
264 std::string relative_path(const std::string& from, const std::string& to);
265
271 std::string absolute_path(const std::string& path);
272
279 std::string convert_to_windows_style(const std::string& path);
280
287 std::string convert_to_unix_style(const std::string& path);
288
295 std::string convert_to_native_style(const std::string& path);
296
302
307 bool is_native_style(const std::string& path);
308
315 bool copy_file(const std::string& original, const std::string& copy);
316
323 bool file_contains_string(const std::string& filename, const std::string& str);
324
330 void read_file_to_string(const std::string& filename, std::string& str);
331
337 void write_string_to_file(const std::string& str, const std::string& filename);
338
339 }
340
341
342} // namespace easy3d
343
344
345#endif // EASY3D_UTIL_FILE_SYSTEM_H
bool delete_directory(const std::string &path)
Deletes the directory 'path' (and its contents will be deleted recursively).
void get_sub_directories(const std::string &path, std::vector< std::string > &subs, bool recursive)
Query subdirectory entries of a directory 'path'.
bool create_directory(const std::string &path)
Creates a directory entitled 'path'.
time_t time_stamp(const std::string &path)
Query the time stamp of a file or directory.
void get_files(const std::string &path, std::vector< std::string > &files, bool recursive)
Queries file entries of a directory 'path'.
std::string name_less_extension(const std::string &path)
Gets file path without last extension (e.g., /a/b/c.Ext => /a/b/c; file.ext1.ext2 => file....
bool is_native_style(const std::string &path)
Checks sif the path contains only the current platform's path separators.
std::string home_directory()
Query the home path for the current user.
std::string executable()
Query the name of this executable.
char native_path_separator()
Gets the path separator of the current platform.
std::string parent_directory(const std::string &path)
Query the parent path from full name of a file or directory (e.g., /a/b/c.Ext => /a/b)
std::string name_less_all_extensions(const std::string &path)
Gets file path without all extensions (e.g., /a/b/c.Ext => /a/b/c; file.ext1.ext2 => file).
bool delete_contents(const std::string &path)
Deletes the contents of the directory 'path' (the directory will not be deleted).
std::string convert_to_native_style(const std::string &path)
Convert a path string such that it uses the current platform's path separators.
void write_string_to_file(const std::string &str, const std::string &filename)
Writes the string into a file.
bool set_current_working_directory(const std::string &path)
Set the current working directory.
std::string simple_name(const std::string &path)
Gets file name without path but with extension (e.g, /a/b/c.Ext => c.Ext)
bool is_directory(const std::string &path)
Tests if 'path' is an existing directory.
std::ifstream::pos_type file_size(const std::string &path)
Query the size of the file.
bool is_file(const std::string &path)
Tests if 'path' is an existing file.
std::string replace_extension(std::string const &path, const std::string &ext)
Replaces the extension of the given file with 'ext'. If the file name does not have an extension,...
bool delete_file(const std::string &path)
Deletes the file 'path'.
std::string time_string(const std::string &path)
Query the time stamp of a file or directory as a string.
bool copy_file(const std::string &original, const std::string &copy)
Makes a copy of an existing file.
std::string convert_to_windows_style(const std::string &path)
Converts the path to Windows style, i.e., forward slashes (/) to back slashes (\‍).
std::string extension(const std::string &path, bool lower=true)
Query the file extension without dot (e.g., /a/b/c.Ext => Ext).
bool is_absolute_path(const std::string &path)
Tests if path is absolute, as !get_path_root(path).empty(). .
std::string absolute_path(const std::string &path)
Converts to absolute path (i.e., removes .. and . from a path string).
std::string relative_path(const std::string &from, const std::string &to)
Compute the relative path from 'from' to 'to'.
std::string convert_to_unix_style(const std::string &path)
Converts the path to Unix style, i.e., back slashes (\‍) to forward slashes (/).
void get_directory_entries(const std::string &path, std::vector< std::string > &entries, bool recursive)
Queries the entries of a directory (including subdirectories and files).
std::string executable_directory()
Query the directory where the executable file is located.
void read_file_to_string(const std::string &filename, std::string &str)
Reads the contents of a file into a string.
bool file_contains_string(const std::string &filename, const std::string &str)
Checks if a file contains string 'str'.
std::string current_working_directory()
Query the current working directory.
std::string path_root(const std::string &path)
Gets root part of a path ("/" or "C:"), or an empty string if none found.
std::string base_name(const std::string &path)
Gets file name without path and last extension (e.g., c:/file.ext1.ext2 => file.ext1; /a/b/c....
bool rename_file(const std::string &old_name, const std::string &new_name)
Rename the file from 'old_name' to 'new_name'.
Definition: collider.cpp:182