Moving Multiple files to different subfolders
-
- Posts: 2
- Joined: 04 May 2019 14:59
Moving Multiple files to different subfolders
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
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
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
-
- Posts: 2
- Joined: 04 May 2019 14:59
Re: Moving Multiple files to different subfolders
Sir, how to use this code? Thanks in Advance!highend wrote: ↑04 May 2019 16:22Code: Select all
foreach($file, listfolder(, , 1), , "e") { moveto gpc($file, "base"), $file, , 2, 2; }
Re: Moving Multiple files to different subfolders
One of my scripts helped you out? Please donate via Paypal
-
- Site Admin
- Posts: 60856
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Moving Multiple files to different subfolders
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.
BTW, this script is kind of the opposite of Flatten Folder, kind of Fatten Folder.
FAQ | XY News RSS | XY Twitter
Re: Moving Multiple files to different subfolders
Thanks for your very useful script.highend wrote: ↑04 May 2019 16:22Code: Select all
foreach($file, listfolder(, , 1), , "e") { moveto gpc($file, "base"), $file, , 2, 2; }
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
Then use
or whatever you need instead of 2 = Overwrite instead...?
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
Re: Moving Multiple files to different subfolders
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'?
Re: Moving Multiple files to different subfolders
This is ONLY for your example file names!
If the real names differ (pattern wise), you need to adapt the used regex!
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
Re: Moving Multiple files to different subfolders
@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
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.
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
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
Re: Moving Multiple files to different subfolders
Thanks a lot!