Moving Multiple files to different subfolders

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Sahilbakshi
Posts: 2
Joined: 04 May 2019 14:59

Moving Multiple files to different subfolders

Post by Sahilbakshi »

Dear All,

I have 50 files in a folder. I want to move those 50 files into 50 subfolders whose names are respectively same as file names. I know XYplorer is enough powerful to do that but I don't know how to do it. If you can help, I would be grateful to you.

Thanks & Regards,
Sahil

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Moving Multiple files to different subfolders

Post by highend »

Code: Select all

    foreach($file, listfolder(, , 1), , "e") {
        moveto gpc($file, "base"), $file, , 2, 2;
    }
One of my scripts helped you out? Please donate via Paypal

Sahilbakshi
Posts: 2
Joined: 04 May 2019 14:59

Re: Moving Multiple files to different subfolders

Post by Sahilbakshi »

highend wrote: 04 May 2019 16:22

Code: Select all

    foreach($file, listfolder(, , 1), , "e") {
        moveto gpc($file, "base"), $file, , 2, 2;
    }
Sir, how to use this code? Thanks in Advance!

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Moving Multiple files to different subfolders

Post by highend »

viewtopic.php?f=7&t=6560

It shows half a dozen ways how to execute scripts
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Moving Multiple files to different subfolders

Post by admin »

Or simply go to your folder, then click menu Scripting | Run Script..., paste that script into the text box, and press OK. :)

BTW, this script is kind of the opposite of Flatten Folder, kind of Fatten Folder. :biggrin:

MaxEnrik
Posts: 107
Joined: 20 Apr 2019 02:34

Re: Moving Multiple files to different subfolders

Post by MaxEnrik »

highend wrote: 04 May 2019 16:22

Code: Select all

    foreach($file, listfolder(, , 1), , "e") {
        moveto gpc($file, "base"), $file, , 2, 2;
    }
Thanks for your very useful script.
XY Copy/Move/Delete 'Confirm' mode is active, but I need to use this script without asking conformation, is it possible to do it within this script, please?
Thanks in advance.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Moving Multiple files to different subfolders

Post by highend »

Then use
moveto gpc($file, "base"), $file, , 2, 2, 2;
or whatever you need instead of 2 = Overwrite instead...?
One of my scripts helped you out? Please donate via Paypal

MaxEnrik
Posts: 107
Joined: 20 Apr 2019 02:34

Re: Moving Multiple files to different subfolders

Post by MaxEnrik »

highend wrote: 08 May 2019 22:35 Then use
moveto gpc($file, "base"), $file, , 2, 2, 2;
or whatever you need instead of 2 = Overwrite instead...?
Just wow, and such an amazing! Thank ya! That is what I wanted!

I would like to ask is below manually action can be done with script, I see partially it can be done with your script.
So, If I select 4 images named 'Image File for - Subfolder Names - (single number)' then run your script and after 4 images move to new subfolders (which is your script can do that) and additionally next to 2 images named 'Image File for - Subfolder Names - 1_don't create folder for me*' these images will move to folder named 'Image File for - Subfolder Names - 1'?

Image

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Moving Multiple files to different subfolders

Post by highend »

This is ONLY for your example file names!
If the real names differ (pattern wise), you need to adapt the used regex!

Code: Select all

    foreach($file, listfolder(, , 1), , "e") {
        $folderName = gpc($file, "base");
        $shortened  = regexreplace($folderName, "^(.+- \d+)(_.*)?$", "$1");
        moveto $shortened, $file, , 2, 2, 2;
    }
One of my scripts helped you out? Please donate via Paypal

MaxEnrik
Posts: 107
Joined: 20 Apr 2019 02:34

Re: Moving Multiple files to different subfolders

Post by MaxEnrik »

@highend - Thank you that worked perfect for my example, I have to try it for real file names and hope it will work with little tweak.

MaxEnrik
Posts: 107
Joined: 20 Apr 2019 02:34

Re: Moving Multiple files to different subfolders

Post by MaxEnrik »

I spent a lot of time that I can find how to improve/modify/customize that script to achieve my goal, I even didn't find a clue to do this 'Creating new folders which files selected (not every files in this current path) and move them into that new subfolders. This was my first part of goal.
So I actually need to do this (for example) I selected 10 files only create single folder for that 10 files. And give a name that a single folder which is 1st file of 10 files ( or which one selected first).
Thanks in advance.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Moving Multiple files to different subfolders

Post by highend »

Code: Select all

    if (get("CountSelected") >= 1) {
        $items = <get SelectedItemsPathNames |>;
        $folderName = gpc(gettoken($items, 1, "|"), "base");
        moveto $folderName, $items, , 2, 2, 2;
    }
One of my scripts helped you out? Please donate via Paypal

MaxEnrik
Posts: 107
Joined: 20 Apr 2019 02:34

Re: Moving Multiple files to different subfolders

Post by MaxEnrik »

Thanks a lot!

Post Reply