Added options to whiledir for filename and no extension.
This commit is contained in:
parent
426b98805c
commit
2bae00acff
@ -11,21 +11,23 @@ namespace jet {
|
|||||||
__whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
__whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
||||||
if(!variableDefined("path"))
|
if(!variableDefined("path"))
|
||||||
throw coreutils::Exception("whiledir tag must specify a path.");
|
throw coreutils::Exception("whiledir tag must specify a path.");
|
||||||
if(!variableDefined("name"))
|
|
||||||
throw coreutils::Exception("whiledir tag requires a name tag.");
|
|
||||||
if(variableDefined("sort") && (variables["sort"] == "true")) {
|
if(variableDefined("sort") && (variables["sort"] == "true")) {
|
||||||
std::vector<std::filesystem::directory_entry> entries;
|
std::vector<std::filesystem::directory_entry> entries;
|
||||||
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str()))
|
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str()))
|
||||||
entries.push_back(entry);
|
entries.push_back(entry);
|
||||||
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) { return a.path() < b.path(); });
|
std::sort(entries.begin(), entries.end(), [](const auto &a, const auto &b) { return a.path() < b.path(); });
|
||||||
for(const auto &entry : entries) {
|
for(const auto &entry : entries) {
|
||||||
variables[variables["name"]] = entry.path();
|
global.variables[variables["fullpath"]] = entry.path();
|
||||||
|
global.variables[variables["filename"]] = entry.path().filename();
|
||||||
|
global.variables[variables["filenamenoextension"]] = entry.path().stem();
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
container.reset();
|
container.reset();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) {
|
for(auto const &entry : std::filesystem::directory_iterator(variables["path"].str())) {
|
||||||
variables[variables["name"]] = entry.path();
|
global.variables[variables["fullpath"]] = entry.path();
|
||||||
|
global.variables[variables["filename"]] = entry.path().filename();
|
||||||
|
global.variables[variables["filenamenoextension"]] = entry.path().stem();
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
container.reset();
|
container.reset();
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,8 @@
|
|||||||
$[ls]
|
$[ls]
|
||||||
<read file="compile" name="file" />
|
<read file="compile" name="file" />
|
||||||
$[filex]
|
$[filex]
|
||||||
<whiledir path="." name="file" sort="true">
|
<whiledir path="." filename="file" fullpath="fullpath" filenamenoextension="noext" sort="true">
|
||||||
#[file]
|
$[file] $[fullpath] $[noext]
|
||||||
</whiledir>
|
</whiledir>
|
||||||
</html>
|
</html>
|
||||||
</jet>
|
</jet>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user