Question about XCopy from Script

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
VeeGee

Question about XCopy from Script

Post by VeeGee »

Good morning all,
I have a small script that is loaded/run via the hamburger menu after I select files in the file list :

Code: Select all

::Move File to Folder;load "MoveFileToFolder.xys";
I can select multiple files in a folder and they are moved into a folder that matches the name. For example, I select the "April Fool's Day (1986).mkv" file and it is moved into the "April Fool's Day (1986)" folder.

Script works fine with just one problem. When I do select multiple files, I get multiple copies of XCopy (so multiple overwrite prompts, etc.) instead of all them being added to a single XCopy queue (like it would do if I manually did any file operations). I like the prompt and didn't script the automatic overwrite option, but now I have to click through multiple XCopy windows.

Here is the script, is there a problem with the coding ?

Code: Select all

    foreach($item, <get SelectedItemsPathNames |>) {
        $base   = gpc($item, "base");
        $ext    = gpc($item, "ext");
        $folder = $base;
        moveto "<curpath>\$folder", $item, , 2;
    }

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

Re: Question about XCopy from Script

Post by highend »

That's the way it works if you call a moveto on every loop?

Build a list of destination files instead and use a rename with the "l" mode _after_ the loop.
Configuration | General | Sort and Rename | Rename | [x] Allow move on rename must be ticked for this to work...
One of my scripts helped you out? Please donate via Paypal

VeeGee

Re: Question about XCopy from Script

Post by VeeGee »

Thanks for the tip! I put this together and it is working ! I also borrowed a few lines of code from one of your scripts. I'm assuming it could be cleaned up and made a little smaller, but it does work and (for me) it is easy to follow.

Code: Select all

    $selectedActive = get("SelectedItemsPathNames", <crlf>, "a");
    $cntItemsActive = gettoken($selectedActive, "count", <crlf>);

	if ($cntItemsActive >= 1) {
		$filelist = "";
		foreach($item, <get SelectedItemsPathNames |>) {
			$base = gpc($item, "base");
			$filename = gpc($item, "file");
			$folder = $base;
			// moveto "<curpath>\$folder", $item, , 2;
			$filelist .= "<curpath>\$folder\$filename" . "|";
		}
		rename "l", $filelist, "p", , 129;
	}

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

Re: Question about XCopy from Script

Post by highend »

This does exactly the same...

Code: Select all

    $list  = "";
    $items = <get SelectedItemsPathNames <crlf>>;
    foreach($item, $items, <crlf>, "e") {
        $list .= <curpath>. "\" . gpc($item, "base") . "\" . gpc($item, "file") . <crlf>;
    }
    if ($list) { rename "l", $list, "p", $items, 129; }
One of my scripts helped you out? Please donate via Paypal

VeeGee

Re: Question about XCopy from Script

Post by VeeGee »

Thank you for the help and the alternate version.

Post Reply