Find # of Items in folders

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
armsys
Posts: 557
Joined: 10 Mar 2012 12:40
Location: Hong Kong

Find # of Items in folders

Post by armsys »

How to list folders which contains only, say, 5, items?
Thanks in advance.

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

Re: Find # of Items in folders

Post by highend »

No time to make this more efficient atm...

Code: Select all

    $limitFiles = 5;
    $result = "";
    foreach($folder, quicksearch("* /d", "<curpath>", "|")) {
        $files = quicksearch("* /f", $folder);
        if (gettoken($files, "count", "<crlf>") == $limitFiles) {
            $result = $result . $folder . "<crlf>";
        }
    }
    if ($result) {
        text "Folder(s) with more than " . $limitFiles . " file(s):<crlf 2>". $result;
    } else {
        status "No appropriate folders found...", "8B4513", "stop";
    }
One of my scripts helped you out? Please donate via Paypal

armsys
Posts: 557
Joined: 10 Mar 2012 12:40
Location: Hong Kong

Re: Find # of Items in folders

Post by armsys »

Hi highend,
Thanks a million for your quick script.

armsys
Posts: 557
Joined: 10 Mar 2012 12:40
Location: Hong Kong

Re: Find # of Items in folders

Post by armsys »

Highend's script refuses to work with an error msg:
The current script appears to be recursive.
The stack size is 0.

Is there a simple way to find all folders containing only 5 files thru the Find File tab (F12)?

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

Re: Find # of Items in folders

Post by highend »

I let that script run on 6709 folders, 37092 files, 85,2 GB of data and didn't get a recursion warning...

Anyway, try this.

Code: Select all

    $limitFiles = 5;

    setting "AllowRecursion", 1;
    $folders = quicksearch("* /d", "<curpath>", "|");
    $result = "";
    foreach($folder, $folders) {
        $files = quicksearch("* /f", $folder);
        if (gettoken($files, "count", "<crlf>") == $limitFiles) {
            $result = $result . $folder . "<crlf>";
        }
    }
    if ($result) {
        text "Folder(s) with more than " . $limitFiles . " file(s):<crlf 2>". $result;
    } else {
        status "No appropriate folders found...", "8B4513", "stop";
    }
One of my scripts helped you out? Please donate via Paypal

Post Reply