Copy/Move to inactive pane with custom Rename

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Ankhman
Posts: 3
Joined: 20 Aug 2023 19:59

Copy/Move to inactive pane with custom Rename

Post by Ankhman »

Hi there.

I absolutely love XYPlorer. It's now my go-to manager and I've already got several clients using it.

I apologize if this has been asked/answered, or if the answer is in an obvious place that I have been unable to locate. I have spent at least a few hours over the last few months looking, trying to create a script, etc. and am still at zero, so I am asking you fine people for assistance. This is a command I would likely use 100+ times a day, so having it would be enormously time saving.

My goal:

-Press a programmed hotkey (one key for the custom 'copy' and one key for my custom 'move' - so different keys) and..
-Selected file/files/folders in the active pane are marked to be copied/moved to the inactive pane.
-*Each selected file/folder selected automatically prompts with an active pop-up box to rename the file/folder.
-The box auto-populates with the current file/folder name, with the actual file name automatically highlighted and with focus (so that if I start typing it would replace the file name, or I could click inside the file name to add/edit/etc.). This auto-highlight would NOT highlight the ".FILEEXT", only the file name itself.
-On pressing the 'RETURN/ENTER' key, the file would then copy/move to the inactive pane with the new name (or with the current name if no changes were made to the highlighted text), or return to '*' above to start the rename process again for the next file/folder in the highlighted list.
-If the file/folder name already exists, the pop-up box would remain with a 'file/folder name already exists' notification, with the original file/folder name restored and highlighted with focus (starting over).
-When the list is done copying/moving/renaming all files, all boxes close, I'm back looking at my 2 pane layout.

Hopefully this is clear. If you are able to help, please let me know if you have any questions or require any clarifications. If I am bypassing traditional methods of asking for help, or have missed a better way to request assistance, I apologize in advance. I appreciate any help I can get with accomplishing these goals.

Long days and pleasant nights! 8)
Jeff

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

Re: Copy/Move to inactive pane with custom Rename

Post by highend »

E.g.:

Code: Select all

    end (get("#800") != 1), "No dual pane active, aborted!";

    $items        = <get SelectedItemsPathNames>;
    $inactivePath = get("path", "i");
    end (!$items), "No item(s) selected, aborted!";

    setting "BackgroundFileOps", 0;
    $i = 1;
    while (true) {
        $item   = gettoken($items, $i, <crlf>);
        $isFile = (exists($item) == 1) ? true : false;
        if ($item == "") { break; }

        $base = gpc($item, "base");
        $ext  = gpc($item, "ext");
        if ($isFile) {
            $newName = GetNewName($item, "Enter new file name for " . quote($base . "." . $ext));
            if ($newName == "" && regexmatches($newName, "(<|>|:|""|/|\\|\||\?|\*)")) { $i++, continue; }
        } else {
            $newName = GetNewName($item, "Enter new folder name for " . quote($base));
            if ($newName == "" && regexmatches($newName, "(<|>|:|""|/|\\|\||\?|\*)")) { $i++, continue; }
        }

        if ($isFile) {
            while (exists($inactivePath . "\" . $newName . "." . $ext) == 1) {
                $newName = GetNewName($item, "File " . quote($base . "." . $ext) . " already exists in other pane!");
            }
            $dstItem = $inactivePath . "\" . $newName . "." . $ext;
        } else {
            while (exists($inactivePath . "\" . $newName) == 2) {
                $newName = GetNewName($item, "Folder " . quote($base) . " already exists in other pane!");
            }
            $dstItem = $inactivePath . "\" . $newName;
        }
        if ($newName == "") { continue; }
        copyitem $item, $dstItem;
        $i++;
    }


function GetNewName($item, $topic) {
    return input($topic, , gpc($item, "base"), 4:="", 5:=350);
}
One of my scripts helped you out? Please donate via Paypal

Ankhman
Posts: 3
Joined: 20 Aug 2023 19:59

Re: Copy/Move to inactive pane with custom Rename

Post by Ankhman »

This is excellent Highend, and so fast! Paypal thanks already sent to you.

I'm happy if this is as good as it gets, but I have some questions/tweaks if you're able. I realize some of these are nitpicks but I figure it can't hurt to ask. :)

1. Is it possible to modify this to be a 'move' script, in addition to the copy script? Exact same functionality, but with a 'move' result for the selected/renamed items as opposed to a copy.
2. Is it possible when there are multiple items to add them to the background queue instead of processing them immidiately? Currently if I select multiple items and run the script, it will complete the copy of the 1st item before moving on to the rename prompt for the 2nd item, etc. This can be troubling when copying large files (which I do often).
3. Once I run the script, I can't click 'cancel' or the X or the escape key to abort the process. It basically won't do anything other than wait for me to press return and complete the script. Am I missing something?
4. Is it possible to change the size of the rename window that pops up to make it larger? It's rather small.

Also, a question: I tried to get a hotkey to run the script from the script folder (so that I can place it in an .xys file and it will be backed up when I run backups, etc.) but was unable to figure out how to assign a hotkey to a specific script using 'customize keyboard shortcuts'. I was able to get it to work by using user>manage commands, but would prefer to use a hotkey to run the script from the scripts folder.

Again, thank you for your speedy help! This is a HUGE improvement to my workflow without even addressing the items above.

Look forward to your ongoing assistance!

Jeff

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

Re: Copy/Move to inactive pane with custom Rename

Post by highend »

Code: Select all

    end (get("#800") != 1), "No dual pane active, aborted!";

    $items        = <get SelectedItemsPathNames>;
    $inactivePath = get("path", "i");
    end (!$items), "No item(s) selected, aborted!";

    setting "BackgroundFileOps", 0;
    $i    = 1;
    $toDo = "";
    while (true) {
        $item   = gettoken($items, $i, <crlf>);
        $isFile = (exists($item) == 1) ? true : false;
        if ($item == "") { break; }

        $base = gpc($item, "base");
        $ext  = gpc($item, "ext");
        if ($isFile) {
            $newName = GetNewName($item, "Enter new file name for " . quote($base . "." . $ext));
            if ($newName == "" && regexmatches($newName, "(<|>|:|""|/|\\|\||\?|\*)")) { $i++, continue; }
        } else {
            $newName = GetNewName($item, "Enter new folder name for " . quote($base));
            if ($newName == "" && regexmatches($newName, "(<|>|:|""|/|\\|\||\?|\*)")) { $i++, continue; }
        }

        if ($isFile) {
            while (exists($inactivePath . "\" . $newName . "." . $ext) == 1) {
                $newName = GetNewName($item, "File " . quote($base . "." . $ext) . " already exists in other pane!");
            }
            $dstItem = $inactivePath . "\" . $newName . "." . $ext;
        } else {
            while (exists($inactivePath . "\" . $newName) == 2) {
                $newName = GetNewName($item, "Folder " . quote($base) . " already exists in other pane!");
            }
            $dstItem = $inactivePath . "\" . $newName;
        }
        if ($newName == "") { continue; }
        if ($isFile) {
            // $toDo .= "copy /Y " . quote($item) . " " . quote($dstItem) . " >NUL 2>NUL" . <crlf>;
            $toDo .= "move /Y " . quote($item) . " " . quote($dstItem) . " >NUL 2>NUL" . <crlf>;
        } else {
            // $toDo .= "robocopy " . quote($item) . " " . quote($dstItem) . " /E /R:0 /DCOPY:T >NUL 2>NUL" . <crlf>;
            $toDo .= "robocopy " . quote($item) . " " . quote($dstItem) . " /E /MOVE >NUL 2>NUL" . <crlf>;
        }
        $i++;
    }

    if ($toDo) {
        $batFile = "%TEMP%\~XYplorer_process_files.bat";
        $result = writefile($batFile, $toDo, , "utf8");
        run lax("$batFile"), "%TEMP%", 1, 0;
    }


function GetNewName($item, $topic) {
    return input($topic, , gpc($item, "base"), , 5:=350);
}
01. Atm it's a move script
If you want it to be a copying one, look at this part and remove the // for the first lines in each clause and add them to the second lines

Code: Select all

        if ($isFile) {
            // $toDo .= "copy /Y " . quote($item) . " " . quote($dstItem) . " >NUL 2>NUL" . <crlf>;
            $toDo .= "move /Y " . quote($item) . " " . quote($dstItem) . " >NUL 2>NUL" . <crlf>;
        } else {
            // $toDo .= "robocopy " . quote($item) . " " . quote($dstItem) . " /E /R:0 /DCOPY:T >NUL 2>NUL" . <crlf>;
            $toDo .= "robocopy " . quote($item) . " " . quote($dstItem) . " /E /MOVE >NUL 2>NUL" . <crlf>;
        }
MAKE SURE YOU TEST IT EXTENSIVELY BEFORE USING IT WITH REAL DATA!

02. Implemented
03. & 04. Changed: input($topic, , gpc($item, "base"), , 5:=350);
Change the value (350) again to make it broader
I was able to get it to work by using user>manage commands
Great. Did you notice that you can assign the hotkey for it right there ("Assign Keyboard Shortcut" button in the same interface)? :biggrin:
One of my scripts helped you out? Please donate via Paypal

Ankhman
Posts: 3
Joined: 20 Aug 2023 19:59

Re: Copy/Move to inactive pane with custom Rename

Post by Ankhman »

Unparalleled delight! This is EXACTLY what I was trying to accomplish. Thank you so much Highend! DoublePlusGood!!

Jeff

Post Reply