Need help to rewrite a simple script

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Setherial
Posts: 8
Joined: 03 Aug 2017 20:29

Need help to rewrite a simple script

Post by Setherial »

Hi there. I need some help to mod a script I took from the script forum.

The following script adds parent folder name to the selected files:
C:\ExampleFolder\File001.txt ---> C:\ExampleFolder\ExampleFolder - File001.txt

Code: Select all

setting "BackgroundFileOps", 0;
    $curBase = gettoken("<curpath>", -1, "\");
    foreach($file, "<get SelectedItemsPathNames |>") {
        $newName = $curBase . " - " . getpathcomponent($file, "file");
        renameitem($newName, $file, , "-01");
    }
I would like the script to do something like this:
C:\ExampleFolder\File001.txt ---> C:\ExampleFolder\File001 [ExampleFolder].txt

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

Re: Need help to rewrite a simple script

Post by highend »

Code: Select all

    setting "BackgroundFileOps", 0;
    foreach($item, "<get SelectedItemsPathNames |>") {
        $parent = replace(gpc($item, "parent"), ":");
        if (exists($item) == 2) { $newName = gettoken($item, -1, "\") . " [$parent]"; }
        else { $newName = gpc($item, "base") . " [$parent]." . gpc($item, "ext"); }
        renameitem($newName, $item, , "-01");
    }
One of my scripts helped you out? Please donate via Paypal

Setherial
Posts: 8
Joined: 03 Aug 2017 20:29

Re: Need help to rewrite a simple script

Post by Setherial »

highend wrote:

Code: Select all

    setting "BackgroundFileOps", 0;
    foreach($item, "<get SelectedItemsPathNames |>") {
        $parent = replace(gpc($item, "parent"), ":");
        if (exists($item) == 2) { $newName = gettoken($item, -1, "\") . " [$parent]"; }
        else { $newName = gpc($item, "base") . " [$parent]." . gpc($item, "ext"); }
        renameitem($newName, $item, , "-01");
    }
That was really quick, you're teh man!

it works like a charm, thank you!!!

Post Reply