Quick Folder View Settings

Discuss and share scripts and script files...
Post Reply
highend
Posts: 14594
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Quick Folder View Settings

Post by highend »

This one is about getting a specific folder view depending on how many files of one / multiple types are in the current directory...

There are only two variables to modify:

$percent = The value for how many files (as a percentage of all files) at which a folder view get's activated
$types = The lines that define the view mode and the extensions that have to match

The view mode is separated from the extensions via a bar character "|" and the extensions are delimited via a semicolon.
You can use the XY internal general file types here!
These currently are:
{:Text};{:Image};{:Photo};{:Audio};{:Video};{:Media};{:Font};{:Vector};{:Web};{:Office};{:Archive};{:Executable}

Put this script in a user defined command and execute it e.g. from a user defined button or a keyboard shortcut...

Code: Select all

// === CONFIGURE VARIABLES #BEGIN ===

    $percent = 26;

    $types = <<<>>>
// View command | Extensions
#302|*.doc;*.txt;{:Office}
#306|*.jpg;*.png;*.tiff
>>>;

// === CONFIGURE VARIABLES #END =====

/*
    {#View}                         | Command
    =========================================
    0 = Details                     |    #302
    1 = Details with Thumbnails #1  |    #303
    2 = List                        |    #304
    3 = Small Icons                 |    #305
    4 = Thumbnails #1               |    #306
    5 = Thumbnails #2               |    #307
    6 = Thumbnails #3               |    #308
    7 = Large Icons                 |    #309
    8 = Small Tiles                 |    #313
    9 = Large Tiles                 |    #314

    Generic file type "variables"
    =============================
    {:Text}
    {:Image}
    {:Photo}
    {:Audio}
    {:Video}
    {:Media}
    {:Font}
    {:Vector}
    {:Web}
    {:Office}
    {:Archive}
    {:Executable}
*/

    $files      = listpane(, , 1+4);
    $filesCount = gettoken($files, "count", "|");
    $types      = regexreplace($types, "^//.*\r?\n");
    $curView    = get("View");

    if !($filesCount) { status "No file(s) in current directory, no view change necessary!", "8B4513", "stop"; end 1==1; }

    $command = "";
    foreach($entry, $types, "<crlf>", "e") {
        $extensions = gettoken($entry, 2, "|");

        if (strpos($extensions, "{") != -1) {
            $resolvedExtensions = "";
            foreach($ext, $extensions, ";", "e") {
                if (regexmatches($ext, "\{:[a-z0-9]+}")) { $resolved = get("genericfiletype", $ext, ";"); }
                else { $resolved = $ext; }
                $resolvedExtensions = $resolvedExtensions . $resolved . ";";
            }
            $extensions = $resolvedExtensions;
        }
        $extensions = formatlist($extensions, "sde", ";");

        $typeCount = gettoken(formatlist($files, "f", , replace($extensions, ";", "|"), "f"), "count", "|");
        if (($typeCount / ($filesCount / 100)) < $percent) { continue; }
        $command = gettoken($entry, 1, "|");
        break;
    }

    if ($command) {
        if ($command == "#302" && $curView ==  0 ||
            $command == "#303" && $curView ==  1 ||
            $command == "#304" && $curView ==  2 ||
            $command == "#305" && $curView ==  3 ||
            $command == "#306" && $curView ==  4 ||
            $command == "#307" && $curView ==  5 ||
            $command == "#308" && $curView ==  6 ||
            $command == "#309" && $curView ==  7 ||
            $command == "#313" && $curView ==  8 ||
            $command == "#314" && $curView ==  9) {
            status "No view change necessary!", "8B4513", "stop"; end 1==1;
        }
        load "$command", , "s";
    }
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 14594
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Quick Folder View Settings

Post by highend »

<reserved>
One of my scripts helped you out? Please donate via Paypal

huyaowen
Posts: 26
Joined: 19 Nov 2015 09:52

Re: Quick Folder View Settings

Post by huyaowen »

RRR.jpg
RRR.jpg (36.86 KiB) Viewed 4350 times
This error may ocurred when only folders exists.

btw,click this custom button just change the view between list and thumbnail.

highend
Posts: 14594
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Quick Folder View Settings

Post by highend »

This error may occurred when only folders exists.
I've added a check to take that into account -> It ends when only folders exist in the current folder
btw,click this custom button just change the view between list and thumbnail.
You mean that it toggles the view? I've added a check for that as well
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 14594
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Quick Folder View Settings

Post by highend »

So, does it work now?
One of my scripts helped you out? Please donate via Paypal

huyaowen
Posts: 26
Joined: 19 Nov 2015 09:52

Re: Quick Folder View Settings

Post by huyaowen »

thanks.
I use a custom button for the script.then,how this button works automatically?

highend
Posts: 14594
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Quick Folder View Settings

Post by highend »

?

This thread is called "Quick..." not "Auto..."
xy doesn't support automatic events (internal name "custom event actions") yet...
One of my scripts helped you out? Please donate via Paypal

huyaowen
Posts: 26
Joined: 19 Nov 2015 09:52

Re: Quick Folder View Settings

Post by huyaowen »

Thanks anyway

Post Reply