Page 1 of 1

Moving Multiple files to different subfolders

Posted: 04 May 2019 16:07
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

Re: Moving Multiple files to different subfolders

Posted: 04 May 2019 16:22
by highend

Code: Select all

    foreach($file, listfolder(, , 1), , "e") {
        moveto gpc($file, "base"), $file, , 2, 2;
    }

Re: Moving Multiple files to different subfolders

Posted: 04 May 2019 16:27
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!

Re: Moving Multiple files to different subfolders

Posted: 04 May 2019 16:33
by highend
viewtopic.php?f=7&t=6560

It shows half a dozen ways how to execute scripts

Re: Moving Multiple files to different subfolders

Posted: 08 May 2019 14:39
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:

Re: Moving Multiple files to different subfolders

Posted: 08 May 2019 22:15
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.

Re: Moving Multiple files to different subfolders

Posted: 08 May 2019 22:35
by highend
Then use
moveto gpc($file, "base"), $file, , 2, 2, 2;
or whatever you need instead of 2 = Overwrite instead...?

Re: Moving Multiple files to different subfolders

Posted: 08 May 2019 23:40
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

Re: Moving Multiple files to different subfolders

Posted: 09 May 2019 10:06
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;
    }

Re: Moving Multiple files to different subfolders

Posted: 09 May 2019 12:49
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.

Re: Moving Multiple files to different subfolders

Posted: 13 May 2019 16:13
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.

Re: Moving Multiple files to different subfolders

Posted: 13 May 2019 16:30
by highend

Code: Select all

    if (get("CountSelected") >= 1) {
        $items = <get SelectedItemsPathNames |>;
        $folderName = gpc(gettoken($items, 1, "|"), "base");
        moveto $folderName, $items, , 2, 2, 2;
    }

Re: Moving Multiple files to different subfolders

Posted: 13 May 2019 16:47
by MaxEnrik
Thanks a lot!