#include "__whiledir.h" #include "Exception.h" #include "__mysql.h" #include #include #include #include namespace jet { __whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) { if(!variableDefined("path")) throw coreutils::Exception("whiledir tag must specify a path."); resolveKeyword("path"); resolveKeyword("sort"); if(variableDefined("sort") && (variables["sort"] == "true")) { std::vector entries; for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) entries.push_back(entry); std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) { return a.path() < b.path(); }); for(const auto &entry : entries) { if(variableDefined("fullpath")) { resolveKeyword("fullpath"); global.variables[variables["fullpath"]] = entry.path(); } if(variableDefined("filename")) { resolveKeyword("filename"); global.variables[variables["filename"]] = entry.path().filename(); } if(variableDefined("filenamenoextension")) { resolveKeyword("filenamenoextension"); global.variables[variables["filenamenoextension"]] = entry.path().stem(); } processContainer(container); container.reset(); } } else { for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) { if(variableDefined("fullpath")) { resolveKeyword("fullpath"); global.variables[variables["fullpath"]] = entry.path(); } if(variableDefined("filename")) { resolveKeyword("filename"); global.variables[variables["filename"]] = entry.path().filename(); } if(variableDefined("filenamenoextension")) { resolveKeyword("filenamenoextension"); global.variables[variables["filenamenoextension"]] = entry.path().stem(); } processContainer(container); container.reset(); } } } }