Page 1 of 1
Script request: Label folder which have specific files within it
Posted: 20 Jun 2017 02:27
by karimmaster101
Hello, I am looking for a script to label folders if they have .jpg files inside it or inside one of its sub-folders.
Ex. (C:\folder01\newone) the "newone" folder have .jpg files so I want the script to label the "newone" folder and the "folder01" too.
Note: the .jpg files could be deeper.
I imagine the way it works will be like: it grabs current path > search for .jpg files > label .jpgs folders till reaching the current path.
I hope that I explained the idea clearly and you got it.
Thanks in advance
Re: Script request: Label folder which have specific files within it
Posted: 20 Jun 2017 07:43
by highend
It does NOT clear any previous labels in folders that DO NOT contain *jpgs!
Code: Select all
// Color name needs to exist in:
// Configuration | Tags | Customize up to 15 Label captions and colors
$labelColor = "Orange";
// Should the current path be labeled as well if it contains .jpgs?
// Can be true or false
$labelCurPath = false;
// ========================================================================
// == DO NOT CHANGE ANYTHING BELOW IF YOU DO NOT KNOW WHAT YOU ARE DOING ==
// ========================================================================
$results = quicksearch("*.jpg");
end !$results, "No .jpg files found, aborted!";
$matches = regexreplace($results, "[^\\]+\.jpg$");
$matches = formatlist($matches, "dn", <crlf>);
// Find only the deepest nested subfolders
$folders = "";
while ($i++ < gettoken($matches, "count", <crlf>)) {
$line = gettoken($matches, $i, <crlf>);
$nextLine = gettoken($matches, $i + 1, <crlf>);
if (strpos($nextLine, $line) == -1) { $folders = $folders . $line . <crlf>; }
}
$folders = regexreplace(trim($folders, <crlf>, "R"), "\\$");
// Build recursive path cascades for each item in $folders
$curpathTokenCount = gettoken(<curpath>, "count", "\");
$cascades = "";
foreach($folder, $folders, <crlf>) {
$i = 0;
$cascade = "";
$folderTokenCount = gettoken($folder, "count", "\");
$loopCount = $folderTokenCount - (($labelCurPath) ? $curpathTokenCount - 1 : $curpathTokenCount);
while ($i++ < $loopCount) {
$cascade = $cascade . gpc($folder, "component", -$i, 1) . <crlf>;
}
$cascades = $cascades . $cascade . <crlf>;
}
$cascades = formatlist($cascades, "den", <crlf>);
// Do the labeling
tagitems(, $labelColor, $cascades);
Re: Script request: Label folder which have specific files within it
Posted: 20 Jun 2017 13:18
by karimmaster101
highend wrote:It does NOT clear any previous labels in folders that DO NOT contain *jpgs!
Code: Select all
// Color name needs to exist in:
// Configuration | Tags | Customize up to 15 Label captions and colors
$labelColor = "Orange";
// Should the current path be labeled as well if it contains .jpgs?
// Can be true or false
$labelCurPath = false;
// ========================================================================
// == DO NOT CHANGE ANYTHING BELOW IF YOU DO NOT KNOW WHAT YOU ARE DOING ==
// ========================================================================
$results = quicksearch("*.jpg");
end !$results, "No .jpg files found, aborted!";
$matches = regexreplace($results, "[^\\]+\.jpg$");
$matches = formatlist($matches, "dn", <crlf>);
// Find only the deepest nested subfolders
$folders = "";
while ($i++ < gettoken($matches, "count", <crlf>)) {
$line = gettoken($matches, $i, <crlf>);
$nextLine = gettoken($matches, $i + 1, <crlf>);
if (strpos($nextLine, $line) == -1) { $folders = $folders . $line . <crlf>; }
}
$folders = regexreplace(trim($folders, <crlf>, "R"), "\\$");
// Build recursive path cascades for each item in $folders
$curpathTokenCount = gettoken(<curpath>, "count", "\");
$cascades = "";
foreach($folder, $folders, <crlf>) {
$i = 0;
$cascade = "";
$folderTokenCount = gettoken($folder, "count", "\");
$loopCount = $folderTokenCount - (($labelCurPath) ? $curpathTokenCount - 1 : $curpathTokenCount);
while ($i++ < $loopCount) {
$cascade = $cascade . gpc($folder, "component", -$i, 1) . <crlf>;
}
$cascades = $cascades . $cascade . <crlf>;
}
$cascades = formatlist($cascades, "den", <crlf>);
// Do the labeling
tagitems(, $labelColor, $cascades);
Thank you very much

Re: Script request: Label folder which have specific files within it
Posted: 20 Jun 2017 15:26
by karimmaster101
highend wrote:It does NOT clear any previous labels in folders that DO NOT contain *jpgs!
Code: Select all
// Color name needs to exist in:
// Configuration | Tags | Customize up to 15 Label captions and colors
$labelColor = "Orange";
// Should the current path be labeled as well if it contains .jpgs?
// Can be true or false
$labelCurPath = false;
// ========================================================================
// == DO NOT CHANGE ANYTHING BELOW IF YOU DO NOT KNOW WHAT YOU ARE DOING ==
// ========================================================================
$results = quicksearch("*.jpg");
end !$results, "No .jpg files found, aborted!";
$matches = regexreplace($results, "[^\\]+\.jpg$");
$matches = formatlist($matches, "dn", <crlf>);
// Find only the deepest nested subfolders
$folders = "";
while ($i++ < gettoken($matches, "count", <crlf>)) {
$line = gettoken($matches, $i, <crlf>);
$nextLine = gettoken($matches, $i + 1, <crlf>);
if (strpos($nextLine, $line) == -1) { $folders = $folders . $line . <crlf>; }
}
$folders = regexreplace(trim($folders, <crlf>, "R"), "\\$");
// Build recursive path cascades for each item in $folders
$curpathTokenCount = gettoken(<curpath>, "count", "\");
$cascades = "";
foreach($folder, $folders, <crlf>) {
$i = 0;
$cascade = "";
$folderTokenCount = gettoken($folder, "count", "\");
$loopCount = $folderTokenCount - (($labelCurPath) ? $curpathTokenCount - 1 : $curpathTokenCount);
while ($i++ < $loopCount) {
$cascade = $cascade . gpc($folder, "component", -$i, 1) . <crlf>;
}
$cascades = $cascades . $cascade . <crlf>;
}
$cascades = formatlist($cascades, "den", <crlf>);
// Do the labeling
tagitems(, $labelColor, $cascades);
I have another request; what if I want to invert the process? (label the folders that doesn't contain .jpg)
I tried to change
to be
Code: Select all
$results = quicksearch("*.jpg /x");
It works well with one level folders but not the same with multi level ones.it seems to need more than just a simple change
Ex: for the current path "c:\myfiles" it will label "c:\myfiles\folder01" in case it didn't find .jpg meanwhile it will label "c:\myfiles\folder02" too though it might have sub-folders which contains .jpg like "c:\myfiles\folder02\imgs\0299.jpg" but the "folder02" itself just have folders.
How could I work around this issue?
Thanks in advance
Re: Script request: Label folder which have specific files within it
Posted: 20 Jun 2017 15:35
by highend
Code: Select all
tagitems(, "", quicksearch("*.jpg /x"));
Re: Script request: Label folder which have specific files within it
Posted: 20 Jun 2017 16:41
by karimmaster101
highend wrote:Code: Select all
tagitems(, "", quicksearch("*.jpg /x"));
Sorry, but I don't get what you mean. should I replace
Code: Select all
tagitems(, $labelColor, $cascades);
with this or what? should I keep
Code: Select all
$results = quicksearch("*.jpg /x");
or not.
Re: Script request: Label folder which have specific files within it
Posted: 20 Jun 2017 16:58
by highend
That line is the full script that does what you've asked for...