move to sibling

Discuss and share scripts and script files...
suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: move to sibling

Post by suslo »

both these variants don't even start the step mode:

Code: Select all

$allItems = <get ItemsNames>;
$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        if (exists("<curpath>\$folder") != 2) { continue; }
        $dst = gettoken($allItems, $indexDst, <crlf>);
        if (exists("<curpath>\$dst") != 2) { end true; }
        $newName = gettoken($folder, 2, " - ", "t", 2);
        if (exists("<curpath>\$dst\$newName") == 2) { end true; }
        rename "l", "<curpath>\$dst\$newName", , "<curpath>\$folder";
    }

Code: Select all

$allItems = <get ItemsNames>;
$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
$dst = gettoken($allItems, $indexDst, <crlf>);
    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        if (exists("<curpath>\$folder") != 2) { continue; }
        if (exists("<curpath>\$dst") != 2) { end true; }
        $newName = gettoken($folder, 2, " - ", "t", 2);
        if (exists("<curpath>\$dst\$newName") == 2) { end true; }
        rename "l", "<curpath>\$dst\$newName", , "<curpath>\$folder";
    }

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

Re: move to sibling

Post by highend »

Invalid indented lines!
One of my scripts helped you out? Please donate via Paypal

suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: move to sibling

Post by suslo »

Code: Select all

        $allItems = <get ItemsNames>;
        $indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
        $dst = gettoken($allItems, $indexDst, <crlf>);
    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        if (exists("<curpath>\$folder") != 2) { continue; }
        if (exists("<curpath>\$dst") != 2) { end true; }
        $newName = gettoken($folder, 2, " - ", "t", 2);
        if (exists("<curpath>\$dst\$newName") == 2) { end true; }
        rename "l", "<curpath>\$dst\$newName", , "<curpath>\$folder";
    }
this code moves+renames the selected folders if the destination folder is right above the selected folders

is it correct that the "1" in this line:

Code: Select all

        $indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
should be changed in case the destination folder is right below the selected folders?

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

Re: move to sibling

Post by highend »

should be changed in case the destination folder is right below the selected folders?
Changed to what?

But apart from that: That's simply not enough. Valid if a single item is selected? Yeah
Still valid for more than one selected item? No
One of my scripts helped you out? Please donate via Paypal

suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: move to sibling

Post by suslo »

if this task:
move+rename the selected folder(s) to the next lower sibling folder
cannot be done by changing that 1 symbol, then what else can i do with the current code?

will it be enough to just make some small changes to it?

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

Re: move to sibling

Post by highend »

Use logic?

If you know the index number of the first selected item, add the count of all selected items to it et voilà,
you have the index for the item under the last selected one...
One of my scripts helped you out? Please donate via Paypal

suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: move to sibling

Post by suslo »

here the destination folder is wrong (the 1st selected folder):

Code: Select all

$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") + gettokenindex(gpc(<selitems>, "file"), $allItems, <crlf>, "i");

Code: Select all

$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") + gettokenindex(gpc(<selitems>, "file"), $allItems, <crlf>, "ic");
here the destination folder is wrong (the 2nd selected folder):

Code: Select all

$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") + gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "ic");

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

Re: move to sibling

Post by highend »

add the count of all selected items
Do any of those commands

Code: Select all

gettokenindex(gpc(<selitems>, "file"), $allItems, <crlf>, "i")
look like that their result holds the number of selected items? They return
an index (a position) of a token in a list of tokens, not a count...

Is gettoken() able to count items?...
One of my scripts helped you out? Please donate via Paypal

suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: move to sibling

Post by suslo »

the destination folder is wrong (the 2nd selected folder):

Code: Select all

$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") + gettoken(gpc(<selitems>, "file"), "count", <crlf>);

Code: Select all

$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") + gettoken(<selitems>, "count", <crlf>);

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

Re: move to sibling

Post by highend »

Code: Select all

gettoken(<selitems>, "count", <crlf>);
Guess why that doesn't return the correct number. Hint: The help file knows why...
One of my scripts helped you out? Please donate via Paypal

suslo
Posts: 178
Joined: 02 Feb 2015 05:02

Re: move to sibling

Post by suslo »

1) this code moves+renames the selected folders if the destination folder is right below the selected folders:

Code: Select all

        $allItems = <get ItemsNames>;
        $indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") + gettoken("<selitems <crlf>>", "count", "<crlf>");
        $dst = gettoken($allItems, $indexDst, <crlf>);
    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        if (exists("<curpath>\$folder") != 2) { continue; }
        if (exists("<curpath>\$dst") != 2) { end true; }
        $newName = gettoken($folder, 2, " - ", "t", 2);
        if (exists("<curpath>\$dst\$newName") == 2) { end true; }
        rename "l", "<curpath>\$dst\$newName", , "<curpath>\$folder";
    }
looks like it works

2) this code moves+renames the selected folders if the destination folder is right above the selected folders:

Code: Select all

        $allItems = <get ItemsNames>;
        $indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
        $dst = gettoken($allItems, $indexDst, <crlf>);
    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        if (exists("<curpath>\$folder") != 2) { continue; }
        if (exists("<curpath>\$dst") != 2) { end true; }
        $newName = gettoken($folder, 2, " - ", "t", 2);
        if (exists("<curpath>\$dst\$newName") == 2) { end true; }
        rename "l", "<curpath>\$dst\$newName", , "<curpath>\$folder";
    }
can you say that both codes are ready and safe to use in real conditions?

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

Re: move to sibling

Post by highend »

Looks ok for me, apart for cases where the selected item is either the first or the last in a list. I would make sure that the script wouldn't continue in that case...
One of my scripts helped you out? Please donate via Paypal

Post Reply