Page 1 of 1

[REQ] Batch movement of files to subdirs in multiple locations

Posted: 04 May 2023 06:53
by 3QQPcr
Is it possible to move multiple files of a certain name to their own respective subdirs, all in a single action?
Or is there a native XY feature that might assist in this operation?

Use case (see screenshot):
I currently run a simple search to isolate the files and folders I wish to work on then drag+drop each individual file into their own subdir but this is very tedious and hardly seems efficient.
If someone smarter than I is able to write a script to automate this process I'd appreciate the help.

Re: [REQ] Batch movement of files to subdirs in multiple locations

Posted: 04 May 2023 07:31
by RalphM
Question: What are we supposed to learn from your screenshot?

Some sample files and folders with full names might go a long way in finding a solution (if you can't share the real ones, make some up that show the way this should be done).
Your description is a bit vague.

Re: [REQ] Batch movement of files to subdirs in multiple locations

Posted: 04 May 2023 09:17
by 3QQPcr
RalphM wrote: 04 May 2023 07:31 Question: What are we supposed to learn from your screenshot?
...
Your description is a bit vague.
The OP screenshot illustrates a standard "Find" query and the items to be moved (*.jpg's located in each folder's root, the only files present in the screenshot) and the respective subfolders each image is to be moved to (*\Proof).
This method of isolating the relevant subfolders and files to be moved is as efficient a way as I've found, at least much more so than moving in and out of each individual folder one at a time.
XYplorer_433P2m50sb.jpg
XYplorer_433P2m50sb.jpg (115.19 KiB) Viewed 1782 times
Currently, moving each item to their respective subfolders is achieved by simply dragging+dropping each individual .jpg into the "Proof" folder beneath it in the "Find" results, which is acceptable when working with only a few files but becomes an inefficient process as the quantity increases.


Another example:
XYplorer_liHI4swuMm.png
XYplorer_liHI4swuMm.png (88.04 KiB) Viewed 1782 times
DESCRIPTION: items returned after a "Find" query for items named "cover" isolates a collection of cover.jpg files and "Cover" subfolders present in each parent folder.
ISSUE: each cover.jpg needs to be moved to their folder's respective "Cover" subfolder.
CURRENT SOLUTION: drag+drop each cover.jpg to their own corresponding "Cover" subfolder, which is an inefficient process for moving anything more than a few files.
Performing this process on a series of 500 folders or even just a fraction of that, but performed daily, is not optimal.


Here's a screenshot after manually moving each cover.jpg to their respective "Cover" subfolder (as you see in the "Path" column).
XYplorer_MetcGo0GjC.png
XYplorer_MetcGo0GjC.png (87.92 KiB) Viewed 1782 times
I'm inquiring as to whether a script could mitigate this manual process or if there's a native XYplorer feature built-in that could assist in this operation.
I could even see a Windows batch script possibly aiding in this operation but I'd need help from brighter minds.
Any suggestion to help automate this process of manually moving individual files into their respective subfolders would be appreciated.

Re: [REQ] Batch movement of files to subdirs in multiple locations

Posted: 04 May 2023 09:24
by highend
So there is ALWAYS only one subfolder in each root folder (where the file exists that should be moved) or is the pattern more like a:

You are searching for a word that is present in both the subfolder and in the file name (like in your examples)?

E.g.: Search = proof, Match folder: Proof, Match file name: <name of a bluray series that also contains "proof" in the file name>
In other words: There could be more than one sub folder but the search ONLY list pairs and the file of the pair should be moved into the folder of the pair?

This is relevant, because if the result list always shows pairs a script wouldn't even need a selection of files to operate correctly...

Re: [REQ] Batch movement of files to subdirs in multiple locations

Posted: 04 May 2023 10:01
by 3QQPcr
highend wrote: 04 May 2023 09:24 In other words: There could be more than one sub folder but the search ONLY list pairs and the file of the pair should be moved into the folder of the pair?
Correct, I currently run an initial search to find pairs of files+folders to relocate (say, for covers), then run a separate search for additional file+folder pairs (say, for proofs).

Re: [REQ] Batch movement of files to subdirs in multiple locations

Posted: 04 May 2023 10:26
by highend

Code: Select all

File sorted above belonging folder (CORRECT):
D:\_test_move_found\a\cache proof me.txt
D:\_test_move_found\a\Proof

Belonging folder sorted above the file (WRONG):
D:\_test_move_found\a\Proof
D:\_test_move_found\a\cache proof me.txt
So make sure that you sort your search result by path^^

You don't need to do any selections after the search has finishes, just start the script...

Code: Select all

    $report = trim(report("{fullname}{Dir \||}<crlf>"), <crlf>, "R");
    end (!$report), "No visible item(s) in current pane, aborted!";

    // We are expecting pairs of found items (one file + one folder in the same root)!
    $cntItems = gettoken($report, "count", <crlf>);

    $log = "";
    while ($i++ < $cntItems) {
        $item   = gettoken($report, $i, <crlf>);
        $isFile = (substr($item, -1) != "\") ? true : false;

        // File above belonging folder
        if ($isFile) {
            $dst = gettoken($report, $i + 1, <crlf>);
            // root folder must be part of $item
            $root  = gpc($dst, "path");
            $found = strpos($item, $root, 0, 1);
            if (substr($dst, -1) == "\" && $found != -1) {
                $log .= "Moved " . quote($item) . " INTO " . quote($dst) . <crlf>;
                moveto $dst, $item, , 0, 2, 4, 1, 0, 0, 1, 0, 0;
            }
        }
    }
    if(!$log) { $log = "Nothing happened!<crlf 2>Maybe files were sorted ABOVE their belonging folder?"; }
    text $log;

Re: [REQ] Batch movement of files to subdirs in multiple locations

Posted: 04 May 2023 13:04
by 3QQPcr
highend wrote: 04 May 2023 10:26 You don't need to do any selections after the search has finishes, just start the script...
Impressive, this script performs better than I imagined!
Moved "C:\...\test.s01e01.1080p.bluray\sample.mkv" INTO "C:\...\test.s01e01.1080p.bluray\sample\"
Moved "C:\...\test.s01e02.1080p.bluray\sample.mkv" INTO "C:\...\test.s01e02.1080p.bluray\sample\"
Moved "C:\...\test.s01e03.1080p.bluray\sample.mkv" INTO "C:\...\test.s01e03.1080p.bluray\sample\"
I really appreciate your time and effort, hopefully this will help other users too.