Page 1 of 1

Auto putting files in folders

Posted: 16 Jun 2017 11:23
by devilparada
I have around 1000 files in folder. I want to divide those files and put them in 50 folders , 20 images in each new folder. How i can do that?

Re: Auto putting files in folders

Posted: 16 Jun 2017 11:24
by highend
By scripting it

E.g.:

Code: Select all

    $batch = 20; // How many items to put in a folder
    $folderName = "Images-"; // This name will be extended by the script!

    // ========================================================================
    // == DO NOT CHANGE ANYTHING BELOW IF YOU DO NOT KNOW WHAT YOU ARE DOING ==
    // ========================================================================

    $items = <get SelectedItemsPathNames <crlf>>;
    end !$items, "No items selected, aborted!";
    $count = gettoken($items, "count", <crlf>);
    $loops = ($count % $batch) ? ceil($count / $batch) : $count / $batch;

    while ($i++ < $loops) {
        $newFolder = $folderName . (($loops <= 99) ? format($i, "00") : format($i, "000"));
        $blockOfItems = gettoken($items, $batch, <crlf>, , 1);
        $items = gettoken($items, $batch + 1, <crlf>, , 2);

        moveto $newFolder, replace($blockOfItems, <crlf>, "|"), , 2, 2;
    }