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
Script request: Label folder which have specific files within it
-
- Posts: 158
- Joined: 20 May 2011 14:34
Re: Script request: Label folder which have specific files within it
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);
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 158
- Joined: 20 May 2011 14:34
Re: Script request: Label folder which have specific files within it
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
-
- Posts: 158
- Joined: 20 May 2011 14:34
Re: Script request: Label folder which have specific files within it
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
Code: Select all
$results = quicksearch("*.jpg");
Code: Select all
$results = quicksearch("*.jpg /x");
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
Code: Select all
tagitems(, "", quicksearch("*.jpg /x"));
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 158
- Joined: 20 May 2011 14:34
Re: Script request: Label folder which have specific files within it
Sorry, but I don't get what you mean. should I replacehighend wrote:Code: Select all
tagitems(, "", quicksearch("*.jpg /x"));
Code: Select all
tagitems(, $labelColor, $cascades);
Code: Select all
$results = quicksearch("*.jpg /x");
Re: Script request: Label folder which have specific files within it
That line is the full script that does what you've asked for...
One of my scripts helped you out? Please donate via Paypal