Page 3 of 3
Re: move to sibling
Posted: 30 May 2018 13:43
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";
}
Re: move to sibling
Posted: 30 May 2018 13:46
by highend
Invalid indented lines!
Re: move to sibling
Posted: 30 May 2018 14:18
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?
Re: move to sibling
Posted: 30 May 2018 14:21
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
Re: move to sibling
Posted: 30 May 2018 14:36
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?
Re: move to sibling
Posted: 30 May 2018 14:49
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...
Re: move to sibling
Posted: 30 May 2018 16:44
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");
Re: move to sibling
Posted: 30 May 2018 16:55
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?...
Re: move to sibling
Posted: 30 May 2018 17:30
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>);
Re: move to sibling
Posted: 30 May 2018 17:40
by highend
Code: Select all
gettoken(<selitems>, "count", <crlf>);
Guess why that doesn't return the correct number. Hint: The help file knows why...
Re: move to sibling
Posted: 30 May 2018 17:53
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?
Re: move to sibling
Posted: 30 May 2018 20:37
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...