//+------------------------------------------------------------------+ //| FolderClean.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_FOLDEROPS_FOLDERCLEAN_MQH #define MQLARTICLES_UTILS_FILE_FOLDEROPS_FOLDERCLEAN_MQH //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include "Base.mqh" // Com un folder clean pero con posibiad de excluir etc files //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class CFolderOpsClean : public CFolderOpsBase { private: bool m_clean_all; public: CFolderOpsClean(void) : m_clean_all(false) {} ~CFolderOpsClean(void) {} //--- // common flag = bandera de common FILE_COMMON si el dir se ubica en common de lo contrario 0 void SetInitialPass() { m_clean_all = false; } bool CleanFolder(const string& init_dir, int common_flag); }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CFolderOpsClean::CleanFolder(const string &init_dir, int common_flag) { //--- string filename = ""; ::ResetLastError(); long handle = FileFindFirst(init_dir + "*", filename, common_flag); if(handle == INVALID_HANDLE) { LogWarning(StringFormat("Error al comenzar la busqueda, ultimo error = %d, puede ser nomal si no hay archivos", ::GetLastError()), FUNCION_ACTUAL); return true; } //--- do { const string full_filename = init_dir + filename; //--- if(filename[StringLen(filename) - 1] == '\\') { //--- Buscamos si este folder esta en los arc hivos incluidos si lo esta entonces limpiamos todo sin exepcion if(IsFileIncluyed(filename)) m_clean_all = true; //--- Limpieza if(!CleanFolder(full_filename, common_flag)) { LogError(StringFormat("Error al limpiar el folder = %s", filename), FUNCION_ACTUAL); FileFindClose(handle); return false; } m_clean_all = false; } else { //--- if(!m_clean_all) { if(IsFileExcluyed(filename)) continue; if(!IsFileIncluyed(filename)) continue; } //--- ::ResetLastError(); if(!::FileDelete(full_filename, common_flag)) { LogWarning(StringFormat("Fallo al eliminar el archivo = '%s', ultimo error = %d", filename, ::GetLastError()), FUNCION_ACTUAL); } } } while(FileFindNext(handle, filename)); //--- FileFindClose(handle); //--- Si se limpio return true; } //+------------------------------------------------------------------+ #endif // MQLARTICLES_UTILS_FILE_FOLDEROPS_FOLDERCLEAN_MQH