forked from nique_372/TSNStd
165 lines
7 KiB
MQL5
165 lines
7 KiB
MQL5
//+------------------------------------------------------------------+
| |
//| File.mqh |
| |
//| Copyright 2026, Niquel Mendoza. |
| |
//| https://www.mql5.com |
| |
//+------------------------------------------------------------------+
| |
#property copyright "Copyright 2026, Niquel Mendoza."
| |
#property link "https://www.mql5.com/es/users/nique_372"
| |
#property strict
| |
| |
#ifndef TSNSTD_STC_PATH_FILE_MQH
| |
#define TSNSTD_STC_PATH_FILE_MQH
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include "..\\String\\String.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
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) (int(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)
| |
{
| |
const uint lenght = folder_name.Length();
| |
if(lenght && folder_name[lenght - 1] == '\\')
| |
folder_name.Truncate(lenght - 1);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
// a\l\h.py
| |
static __forceinline string CPathUtils::PathGetDirectory(const string& path)
| |
{
| |
//---
| |
const int idx = TSN::CStringFunc::RFindCh(path, '\\', StringLen(path) - 1);
| |
return idx == -1 ? "" : StringSubstrRange(path, 0, idx); // incluye el \
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
static __forceinline string CPathUtils::PathGetDirectoryNoRef(const string& path)
| |
{
| |
//---
| |
const int idx = TSN::CStringFunc::RFindCh(path, '\\', StringLen(path) - 1);
| |
return idx == -1 ? "" : StringSubstrRange(path, 0, idx); // incluye el \
| |
}
| |
| |
// de un path le quita el \\
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static __forceinline string CPathUtils::GetPureFileName(const string& filename)
| |
{
| |
const int in = TSN::CStringFunc::RFindCh(filename, '\\', StringLen(filename) - 1);
| |
return in == -1 ? filename : StringSubstr(filename, in + 1);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
static __forceinline string CPathUtils::GetPureFileNameNoRef(const string filename)
| |
{
| |
const int in = TSN::CStringFunc::RFindCh(filename, '\\', StringLen(filename) - 1);
| |
return in == -1 ? filename : StringSubstr(filename, in + 1);
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static __forceinline bool CPathUtils::FileHasExtension(const string& filename, const string& extension)
| |
{
| |
const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
| |
return in == -1 ? false : (StringSubstr(filename, in) == extension);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static __forceinline string CPathUtils::FileGetExtension(const string& filename)
| |
{
| |
const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
| |
return in == -1 ? "" : StringSubstr(filename, in + 1);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
static __forceinline string CPathUtils::FileGetExtensionNoRef(const string filename)
| |
{
| |
const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
| |
return in == -1 ? "" : StringSubstr(filename, in + 1);
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static __forceinline string CPathUtils::FileRemoveExtension(const string& filename)
| |
{
| |
const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
| |
return in == -1 ? "" : StringSubstr(filename, 0, in);
| |
}
| |
//+------------------------------------------------------------------+
| |
static __forceinline string CPathUtils::FileRemoveExtensionNoRef(const string filename)
| |
{
| |
const int in = TSN::CStringFunc::RFindCh(filename, '.', StringLen(filename) - 1);
| |
return in == -1 ? "" : StringSubstr(filename, 0, in);
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
static __forceinline bool CPathUtils::CreateFolder(string folder_path, bool common_flag)
| |
{
| |
return FolderCreate(folder_path, MQLARTICES_PATHU_COMON_TO_FLAG(common_flag));
| |
}
| |
| |
}
| |
//+------------------------------------------------------------------+
| |
#endif // TSNSTD_STC_PATH_FILE_MQH
|