Change color based on content of folder?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
mrbosco
Posts: 125
Joined: 03 Sep 2011 09:40

Change color based on content of folder?

Post by mrbosco »

Is there a way to change the color of the folder if a file within that folder has been recently updated?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Change color based on content of folder?

Post by highend »

As long as that file is in the selected folder (and not further down in a subfolder of it)?

If the file is modified, the modified timestamp of that folder changes as well. So you
could define several color filters with different colors for different modified ranges...
One of my scripts helped you out? Please donate via Paypal

mrbosco
Posts: 125
Joined: 03 Sep 2011 09:40

Re: Change color based on content of folder?

Post by mrbosco »

What if the file is a subfolder or two down?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Change color based on content of folder?

Post by highend »

colorfilters don't look into single changes for arbitrary files somewhere deep inside a folder structure so
afaik there is no automatism to change the color (at least not if the folder structure is not 100% static).
Scripting could do it but it would require user interaction to fire it... Or an external .ahk tool that
monitors folders and sends a script to that XY instance to change the label for that folder...
One of my scripts helped you out? Please donate via Paypal

mrbosco
Posts: 125
Joined: 03 Sep 2011 09:40

Re: Change color based on content of folder?

Post by mrbosco »

Can you please provide a sample script?
BTW, I don't necessarily need the color of the folder to change.
If I had a way of displaying only folders whose files nested a few layers down have changed recently that would be just as good.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Change color based on content of folder?

Post by highend »

Shows the folders from the current active pane that have a file modified in the last
7 days in a new paperfolder... Modify it as you need

Code: Select all

    $folders = listfolder(, , 2, <crlf>);
    $modifiedFiles = quicksearch("ageM: <= 7 d /limitperdir=1");
    $paperContent = "";
    foreach($folder, $folders, <crlf>, "e") {
        $escaped = regexreplace($folder, "([\\.+(){\[^$])", "\$1");
        if (regexmatches($modifiedFiles, $escaped . "\\")) {
            $paperContent = $paperContent . $folder . <crlf>;
        }
    }
    if ($paperContent) { paperfolder("Modified", $paperContent); }
One of my scripts helped you out? Please donate via Paypal

mrbosco
Posts: 125
Joined: 03 Sep 2011 09:40

Re: Change color based on content of folder?

Post by mrbosco »

I'll give it a try.
Thanks!

mrbosco
Posts: 125
Joined: 03 Sep 2011 09:40

Re: Change color based on content of folder?

Post by mrbosco »

The script works great. However, I'm new to scripting and trying to understand exactly how it works.

Can you please explain what each of the following lines do?

Code: Select all

$escaped = regexreplace($folder, "([\\.+(){\[^$])", "\$1");

Code: Select all

if (regexmatches($modifiedFiles, $escaped)) {
Thanks,
Howie

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Change color based on content of folder?

Post by highend »

I've removed the full quote of the script and added code tags to the two lines in
your posting...

Code: Select all

$escaped = regexreplace($folder, "([\\.+(){\[^$])", "\$1");
I'm replacing all meta characters for the current folder in the loop
with a leading backslash followed by the metacharacter because
I need the escaped path for the following if statement

Code: Select all

if (regexmatches($modifiedFiles, $escaped)) {
The regexmatches requires a regex pattern (done in the previous
explanation) and I'm checking here if the folder exists as a part
in the modified files list
One of my scripts helped you out? Please donate via Paypal

mrbosco
Posts: 125
Joined: 03 Sep 2011 09:40

Re: Change color based on content of folder?

Post by mrbosco »

Thank you!

mrbosco
Posts: 125
Joined: 03 Sep 2011 09:40

Re: Change color based on content of folder?

Post by mrbosco »

Seems to be an issue with the script.

If I have two folders ABC and ABCD and a file is updated within ABCD, both folders ABC and ABCD are in the paper folder even though nothing has been updated in folder ABC.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Change color based on content of folder?

Post by highend »

Screenshot of both folders in the list (last modified date column must be visible as well)?
One of my scripts helped you out? Please donate via Paypal

mrbosco
Posts: 125
Joined: 03 Sep 2011 09:40

Re: Change color based on content of folder?

Post by mrbosco »

I changed the script to

$folders = listfolder(, , 2, <crlf>);
$modifiedFiles = quicksearch("ageM: <= 1 h /limitperdir=1");
$paperContent = "";
foreach($folder, $folders, <crlf>, "e") {
$escaped = regexreplace($folder, "([\\.+(){\[^$])", "\$1");
if (regexmatches($modifiedFiles, $escaped)) {
$paperContent = $paperContent . $folder . <crlf>;
}
}
if ($paperContent) { paperfolder("Modified", $paperContent); }

since I created the folder earlier in the day.

Folder ABC is empty
Folder ABCD has one recently modified file in it.

The script produces both folders ABC and ABCD
Attachments
2017-10-30_13-02-53.jpg
2017-10-30_13-02-53.jpg (23.08 KiB) Viewed 2394 times

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Change color based on content of folder?

Post by highend »

Replace

Code: Select all

if (regexmatches($modifiedFiles, $escaped)) {
with

Code: Select all

if (regexmatches($modifiedFiles, $escaped . "\\")) {
One of my scripts helped you out? Please donate via Paypal

mrbosco
Posts: 125
Joined: 03 Sep 2011 09:40

Re: Change color based on content of folder?

Post by mrbosco »

Thanks!

Post Reply