Page 1 of 1

Find # of Items in folders

Posted: 10 Sep 2015 11:02
by armsys
How to list folders which contains only, say, 5, items?
Thanks in advance.

Re: Find # of Items in folders

Posted: 10 Sep 2015 11:25
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";
    }

Re: Find # of Items in folders

Posted: 10 Sep 2015 11:36
by armsys
Hi highend,
Thanks a million for your quick script.

Re: Find # of Items in folders

Posted: 10 Sep 2015 12:30
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)?

Re: Find # of Items in folders

Posted: 10 Sep 2015 12:37
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";
    }