6 #include "CORE_Object.h"
15 #include "functions_string.h"
77 inline static tBoolean
IsFile(
const tString& f) {
78 return std::filesystem::is_regular_file(f);
84 inline static tBoolean
IsPath(
const tString& p) {
85 return std::filesystem::is_directory(p);
91 inline static tBoolean
Exists(
const tString& f) {
92 return std::filesystem::exists(f);
100 std::filesystem::path p(path);
101 return std::filesystem::create_directories(p);
107 inline static tBoolean
Rename(
const tString& file,
const tString& newFile) {
109 std::filesystem::rename(file,newFile);
120 inline static tBoolean
RemovePath(
const tString& path,
const tBoolean& force) {
123 return (std::filesystem::remove_all(path)!=0);
125 return std::filesystem::remove(path);
127 }
catch(std::exception& e) {
128 std::cerr<<e.what()<<
"\n";
145 return std::filesystem::remove(file);
152 std::vector<tString> files;
155 for_each(files.begin(),files.end(),[&](
const auto& file) {
156 std::filesystem::remove(file);
164 std::vector<tString> files;
167 for_each(files.begin(),files.end(),[&](
const auto& file) {
168 std::filesystem::remove(file);
177 return std::filesystem::path(posix_path).make_preferred().string();
184 inline static void GetPaths(
const tString& path,std::vector<tString>& paths) {
186 if (std::filesystem::exists(path)) {
187 for (
const auto & entry : std::filesystem::directory_iterator(path))
188 if (std::filesystem::is_directory(entry.path())) paths.push_back(entry.path());
196 std::filesystem::path p(aPath);
204 inline static void GetFiles(
const tString& path,std::vector<tString>& files) {
206 if (std::filesystem::exists(path)) {
207 for (
const auto & entry : std::filesystem::directory_iterator(path))
208 if (std::filesystem::is_regular_file(entry.path())) files.push_back(entry.path());
216 inline static void GetFiles(
const tString& path,
const tString& exts,std::vector<tString>& files) {
218 if (std::filesystem::exists(path)) {
220 for (
const auto & entry : std::filesystem::directory_iterator(path)) {
222 functions_string::toLower(ext);
223 if ( (ext.compare(
"")!=0) &&
224 (exts.find(ext)!=tString::npos) &&
225 (std::filesystem::is_regular_file(entry.path()))) files.push_back(entry.path());
235 inline static void GetFiles(
const tString& path,
const tString& prefix,
const tString& exts,std::vector<tString>& files) {
237 if (std::filesystem::exists(path)) {
239 for (
const auto & entry : std::filesystem::directory_iterator(path)) {
241 functions_string::toLower(ext);
242 if ( (ext.compare(
"")!=0) &&
243 (exts.find(ext)!=tString::npos) &&
244 (std::filesystem::is_regular_file(entry.path())) &&
245 (entry.path().filename().string().find(prefix)==0)
246 ) files.push_back(entry.path().filename());
258 inline static tBoolean
CopyFiles(
const tString& sourcePath,
const tString& exts,
259 const tString& destPath,
260 const tBoolean& overwrite) {
262 if (std::filesystem::exists(sourcePath)&&std::filesystem::exists(destPath)) {
265 std::filesystem::copy_options copyOptions;
267 copyOptions=std::filesystem::copy_options::update_existing;
269 for (
const auto & entry : std::filesystem::directory_iterator(sourcePath)) {
271 functions_string::toLower(ext);
272 if ( (ext.compare(
"")!=0) && (exts.find(ext)!=tString::npos) &&
273 (std::filesystem::is_regular_file(entry.path()))) std::filesystem::copy(entry.path(),destPath,copyOptions);
285 inline static tBoolean
CopyFiles(
const tString& sourcePath,
286 const tString& destPath,
287 const tBoolean& overwrite) {
288 if (std::filesystem::exists(sourcePath)&&std::filesystem::exists(destPath)) {
289 std::filesystem::copy_options copyOptions=std::filesystem::copy_options::skip_existing;
292 copyOptions=std::filesystem::copy_options::overwrite_existing;
294 std::filesystem::copy(sourcePath,destPath,copyOptions);
305 inline static tBoolean
CopyFile(
const tString& source,
307 const tBoolean& overwrite) {
308 if (std::filesystem::exists(dest)) {
309 std::filesystem::copy_options copyOptions;
311 copyOptions=std::filesystem::copy_options::overwrite_existing;
312 if (!std::filesystem::equivalent(source,dest)) std::filesystem::copy(source,dest,copyOptions);
315 std::filesystem::copy(source,dest);
323 inline static tBoolean
CopyFile(
const tString& source,
324 const tString& dest) {
333 inline static tBoolean
CopyPath(
const tString& sourcePath,
const tString& destPath) {
334 if (std::filesystem::exists(sourcePath)) {
335 const auto copyOptions = std::filesystem::copy_options::update_existing
336 | std::filesystem::copy_options::recursive;
338 std::filesystem::copy(sourcePath,destPath,copyOptions);
348 inline static void GetContent(
const tString& path,std::vector<tString>& content) {
350 for (
const auto & entry : std::filesystem::directory_iterator(path))
351 content.push_back(entry.path());
359 return std::filesystem::current_path() ;
366 return std::filesystem::absolute(path) ;
373 return std::filesystem::path(file).stem();
381 return std::filesystem::path(file).extension();
388 inline static tString
GetPath(
const tString& file) {
389 return std::filesystem::path(file).parent_path();;
396 return std::filesystem::path(file).filename();
this class describes the file system IO by default write on standart output
Definition: CORE_IO.h:23
static tString GetPath(const tString &file)
get path containing the file
Definition: CORE_IO.h:388
static tBoolean RemovePath(const tString &path)
remove an empty path
Definition: CORE_IO.h:136
static tString GetCurrentPath()
get the current path
Definition: CORE_IO.h:358
static tString GetFileName(const tString &file)
get path containing the file
Definition: CORE_IO.h:395
static void GetFiles(const tString &path, std::vector< tString > &files)
get all the files within the directory
Definition: CORE_IO.h:204
virtual ~CORE_IO(void)
destroy a CORE_IO
Definition: CORE_IO.h:50
static tBoolean RemoveFile(const tString &file)
remove a file
Definition: CORE_IO.h:144
static void GetFiles(const tString &path, const tString &prefix, const tString &exts, std::vector< tString > &files)
get all the files within the directory with extension of the form .ext
Definition: CORE_IO.h:235
static tBoolean CopyFiles(const tString &sourcePath, const tString &destPath, const tBoolean &overwrite)
copy all the files within the directory to destination path
Definition: CORE_IO.h:285
static tBoolean CopyFile(const tString &source, const tString &dest, const tBoolean &overwrite)
copy file
Definition: CORE_IO.h:305
static tString GetSystemPath(const tString &posix_path)
get the system path corresponding to posix path
Definition: CORE_IO.h:176
static tString GetPathName(const tString &aPath)
get all the paths within the directory
Definition: CORE_IO.h:195
static tString GetAbsolutePath(const tString &path)
get the absolute path of the path
Definition: CORE_IO.h:365
static tBoolean IsPath(const tString &p)
return true if the path designed by p is a path
Definition: CORE_IO.h:84
static void GetFiles(const tString &path, const tString &exts, std::vector< tString > &files)
get all the files within the directory with extension of the form .ext
Definition: CORE_IO.h:216
static tBoolean CopyFiles(const tString &sourcePath, const tString &exts, const tString &destPath, const tBoolean &overwrite)
copy all the files with extension within the directory to destination path
Definition: CORE_IO.h:258
static void RemoveAllFiles(const tString &path, const tString &exts)
remove all files with extension within the path
Definition: CORE_IO.h:163
static tBoolean CopyPath(const tString &sourcePath, const tString &destPath)
copy path
Definition: CORE_IO.h:333
static tBoolean Exists(const tString &f)
return true if the file or the path exists
Definition: CORE_IO.h:91
static tBoolean CopyFile(const tString &source, const tString &dest)
copy file
Definition: CORE_IO.h:323
static void GetContent(const tString &path, std::vector< tString > &content)
get all the content files or paths within the directory
Definition: CORE_IO.h:348
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: CORE_IO.h:69
static tBoolean CreatePath(const tString &path)
create a path
Definition: CORE_IO.h:99
static tString GetExtension(const tString &file)
get extension of the file
Definition: CORE_IO.h:380
static tBoolean IsFile(const tString &f)
return true if the file is a regular file
Definition: CORE_IO.h:77
static tBoolean Rename(const tString &file, const tString &newFile)
Definition: CORE_IO.h:107
static void RemoveAllFiles(const tString &path)
remove all files within a path
Definition: CORE_IO.h:151
static tString GetBaseName(const tString &file)
get base name of the file
Definition: CORE_IO.h:372
CORE_IO()
build a CORE_IO
Definition: CORE_IO.h:40
static void GetPaths(const tString &path, std::vector< tString > &paths)
get all the paths within the directory
Definition: CORE_IO.h:184
static tBoolean RemovePath(const tString &path, const tBoolean &force)
remove a path
Definition: CORE_IO.h:120
abstract base class for most classes.
Definition: CORE_Object.h:65
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278