2026-09-01 20:00:53 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| File.mqh |
|
| | | //| Copyright 2026, Niquel Mendoza. |
|
| | | //| https://www.mql5.com/es/users/nique_372 |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Copyright 2026, Niquel Mendoza."
|
| | | #property link "https://www.mql5.com/es/users/nique_372"
|
| | | #property strict
|
| | |
|
| | | #ifndef MQLARTICLES_UTILS_FILE_FILE_MQH
|
| | | #define MQLARTICLES_UTILS_FILE_FILE_MQH
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | #include "..\\FA\\String\\String.mqh"
|
2026-09-01 20:00:53 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | namespace TSN
|
| | | {
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | // c = bool
|
| | | // c << 12 = (con c=False, da 0)
|
| | | // c << 12 = (con c=True, da 4096=FILE_COMMON)
|
| | | // branchles
|
| | | #define MQLARTICES_PATHU_COMON_TO_FLAG(c) ((c) << 12)
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | class CPathUtils
|
| | | {
|
| | | public:
|
| | | CPathUtils(void);
|
| | | ~CPathUtils(void);
|
| | |
|
| | | //---
|
| | | static __forceinline void FolderRemoveBarraInvertida(string& folder_name);
|
| | |
|
| | | //---
|
| | | static __forceinline string PathGetDirectory(const string& path);
|
| | | static __forceinline string PathGetDirectoryNoRef(const string& path);
|
| | |
|
| | | //---
|
| | | static __forceinline string GetPureFileName(const string& filename);
|
| | | static __forceinline string GetPureFileNameNoRef(const string filename);
|
| | |
|
| | | //---
|
| | | static __forceinline bool FileHasExtension(const string& filename, const string& extension);
|
| | |
|
| | | //---
|
| | | static __forceinline string FileGetExtension(const string& filename);
|
| | | static __forceinline string FileGetExtensionNoRef(const string filename);
|
| | |
|
| | | //---
|
| | | static __forceinline string FileRemoveExtension(const string& filename);
|
| | | static __forceinline string FileRemoveExtensionNoRef(const string filename);
|
| | |
|
| | | //---
|
| | | static __forceinline bool CreateFolder(string folder_path, bool common_flag);
|
| | | };
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | static __forceinline void CPathUtils::FolderRemoveBarraInvertida(string& folder_name)
|
2026-09-01 20:00:53 -05:00 | | | {
|
| | | const uint lenght = folder_name.Length();
|
| | | if(lenght && folder_name[lenght - 1] == '\\')
|
| | | folder_name.Truncate(lenght - 1);
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | // a\l\h.py
|
2026-09-12 19:41:52 -05:00 | | | static __forceinline string CPathUtils::PathGetDirectory(const string& path)
|
2026-09-01 20:00:53 -05:00 | | | {
|
| | | //---
|
2026-09-12 19:41:52 -05:00 | | | const int idx = TSN::CStringFunc::RFindCh(path, '\\', StringLen(path) - 1);
|
| | | return idx == -1 ? "" : StringSubstrRange(path, 0, idx); // incluye el \
|
2026-09-01 20:00:53 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | static __forceinline string CPathUtils::PathGetDirectoryNoRef(const string& path)
|
2026-09-01 20:00:53 -05:00 | | | {
|
| | | //---
|
2026-09-12 19:41:52 -05:00 | | | const int idx = TSN::CStringFunc::RFindCh(path, '\\', StringLen(path) - 1);
|
| | | return idx == -1 ? "" : StringSubstrRange(path, 0, idx); // incluye el \
|
2026-09-01 20:00:53 -05:00 | | | }
|
| | |
|
| | | // de un path le quita el \\
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | static __forceinline string CPathUtils::GetPureFileName(const string& filename)
|
2026-09-01 20:00:53 -05:00 | | | {
|
2026-09-12 19:41:52 -05:00 | | | const int in = TSN::CStringFunc::RFindCh(filename, '\\', StringLen(filename) - 1);
|
| | | return in == -1 ? filename : StringSubstr(filename, in + 1);
|
2026-09-01 20:00:53 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | static __forceinline string CPathUtils::GetPureFileNameNoRef(const string filename)
|
2026-09-01 20:00:53 -05:00 | | | {
|
2026-09-12 19:41:52 -05:00 | | | const int in = TSN::CStringFunc::RFindCh(filename, '\\', StringLen(filename) - 1);
|
| | | return in == -1 ? filename : StringSubstr(filename, in + 1);
|
2026-09-01 20:00:53 -05:00 | | | }
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | static __forceinline bool CPathUtils::FileHasExtension(const string& filename, const string& extension)
|
2026-09-01 20:00:53 -05:00 | | | {
|
2026-09-12 19:41:52 -05:00 | | | const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
|
| | | return in == -1 ? false : (StringSubstr(filename, in) == extension);
|
2026-09-01 20:00:53 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | static __forceinline string CPathUtils::FileGetExtension(const string& filename)
|
2026-09-01 20:00:53 -05:00 | | | {
|
2026-09-12 19:41:52 -05:00 | | | const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
|
| | | return in == -1 ? "" : StringSubstr(filename, in + 1);
|
2026-09-01 20:00:53 -05:00 | | | }
|
| | |
|
2026-09-12 19:41:52 -05:00 | | | //+------------------------------------------------------------------+
|
| | | static __forceinline string CPathUtils::FileGetExtensionNoRef(const string filename)
|
2026-09-01 20:00:53 -05:00 | | | {
|
2026-09-12 19:41:52 -05:00 | | | const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
|
| | | return in == -1 ? "" : StringSubstr(filename, in + 1);
|
2026-09-01 20:00:53 -05:00 | | | }
|
| | |
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | static __forceinline string CPathUtils::FileRemoveExtension(const string& filename)
|
2026-09-01 20:00:53 -05:00 | | | {
|
2026-09-12 19:41:52 -05:00 | | | const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
|
| | | return in == -1 ? "" : StringSubstr(filename, 0, in);
|
2026-09-01 20:00:53 -05:00 | | | }
|
| | | //+------------------------------------------------------------------+
|
2026-09-12 19:41:52 -05:00 | | | static __forceinline string CPathUtils::FileRemoveExtensionNoRef(const string filename)
|
2026-09-01 20:00:53 -05:00 | | | {
|
2026-09-12 19:41:52 -05:00 | | | const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
|
| | | return in == -1 ? "" : StringSubstr(filename, 0, in);
|
2026-09-01 20:00:53 -05:00 | | | }
|
| | |
|
2026-09-12 19:41:52 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | static __forceinline bool CPathUtils::CreateFolder(string folder_path, bool common_flag)
|
| | | {
|
| | | return FolderCreate(folder_path, MQLARTICES_PATHU_COMON_TO_FLAG(common_flag));
|
| | | }
|
2026-09-01 20:00:53 -05:00 | | |
|
2026-09-12 19:41:52 -05:00 | | | }
|
2026-09-01 20:00:53 -05:00 | | | //+------------------------------------------------------------------+
|
| | | #endif // MQLARTICLES_UTILS_FILE_FILE_MQH
|