Auto putting files in folders

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
devilparada
Posts: 22
Joined: 05 May 2017 15:16

Auto putting files in folders

Post 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?

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

Re: Auto putting files in folders

Post 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;
    }

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

Post Reply