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 »

when the selected folder and the destination folder have different symbols in the beginnings of their names (for example, band15 and band20), then nothing happens after i run the altered script (with or without the step; command)
so i cannot tell you at which line it fails
all parts of a file folder are separated via a single space
then please say what is the correct separator in this case. if we really need the separator (despite the fact that we don't really have to rename anything in this example)

$newName = gettoken($folder, 2, " ", , 2);           result: nothing happens
$newName = gettoken($folder, 2, ",", , 2);           result: nothing happens
$newName = gettoken($folder, 2, "//", , 2);         result: nothing happens
$newName = gettoken($folder, 2, "<crlf>", , 2);    result: nothing happens
$newName = gettoken($folder, 2, "", , 2);            result: Error: The process cannot access the file because it is being used by another process

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: move to sibling

Post by highend »

So now it is NOT the first part of a folder name that will be the name of the destination folder?

And so: How does gettoken() make sense here? It doesn't...
You can't get a "band15" from a "band20 <something>" name...

In other words, now it is really just the folder above the selected one(s), correct?
$newName = gettoken($folder, 2, " ", , 2); result: nothing happens
$newName = gettoken($folder, 2, ",", , 2); result: nothing happens
$newName = gettoken($folder, 2, "//", , 2); result: nothing happens
$newName = gettoken($folder, 2, "<crlf>", , 2); result: nothing happens
$newName = gettoken($folder, 2, "", , 2); result: Error: The process cannot access the file because it is being used by another process
Em, what the heck are you even trying to do there???

$newName = gettoken($folder, 2, "//", , 2); // By default invalid, not allowed in file or folder names
$newName = gettoken($folder, 2, "<crlf>", , 2); // Same as above
$newName = gettoken($folder, 2, "", , 2); // This would take the 2nd char and all following. I guess that's not what's wanted here...

Show a screenshot of the list pane with the selected files / folders and mark which would be the destination directory
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 »

for some time let's forget about the altered version of the main working script (yes, the altered script is really about just the folder above the selected one(s). in other words: only movement is necessary, while rename is not needed at all)

there are several much more important aspects with the main script:
1) it is only working if the destination folder has the same beginning comparing to the selected folder. example:
The Gathering
The Gathering - 1992 - Always
but it is not working if the destination folder has different beginning comparing to the selected folder. example:
The Gathering [ metal, rock ]
The Gathering - 1992 - Always
2) there could be a variant where the destination folder has different beginning and also contains " - "
example:
The Gathering [ 1992-1997 - metal, 1998-2009 - rock ]
The Gathering - 1992 - Always
now the script is also not working here (because the beginning is again different)
but i wanted to show you this variant just in case (in order to be sure that such variant won't be a problem in the future)


3) i noticed that move+rename is also performed to the next sibling (when the selected folder is above the destination folder). example:
The Gathering - 1992 - Always
The Gathering
this behaviour was not among the aims in the beginning of this thread
but nevertheless this behaviour is useful in some cases like this:
The Gathering - 1992 - Always
The Gathering [ metal, rock ]
so i think that 2 almost identical scripts are needed. with 1 difference between them:
script-1 moves(+renames) the selected folder(s) to the nearest upper sibling folder
script-2 moves(+renames) the selected folder(s) to the nearest lower sibling folder


that was not easy to explain. i tried. please ask questions if something is not very clear

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: move to sibling

Post by highend »

It moves the selected items to the folder that has the name of the first token of the selected folders. Your example in the first post didn't mention those cornercases from the last...

What are you waiting for, code it?

How can you find out the name of the item that is above the FIRST selected one?
gettokenindex() is able to find the number of the first selected item (with the appropriate variable that contains these)...
gettoken() can use that index to get that destination (folder) name
And apart of that, again (and again), a loop over the selected ones and a moveto / rename in list mode...

In other words: Basically the same building blocks like in the first example with minimal variation...
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 »

Your example in the first post didn't mention
- my example in the first post also didn't mention any kind of "the first token"
- the task was described clearly (what to move and where to move, what to rename and how to rename)

- i think that the 'example' word does not necessarily mean that in real conditions the script will always have very similar titles (absolutely different folder names should be taken into account when creating a code like this)

- i'm not a robot, i may forget to mention some aspects in the beginning, and i may recollect them further
- sometimes some new circumstances may appear after the moment when the thread was created (and as a result, i may add something to the initial task or alter it partially. do you have all your scripts created and ready right from the first attempt?)

this does not work:

Code: Select all

    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        if (exists("<curpath>\$folder") != 2) { continue; }
        $first = gettokenindex("<selitem>", "$folder", "<crlf>")
        $first = gettoken($folder, 1);
        if (exists("<curpath>\$first") != 2) { end true; }
        $newName = gettoken($folder, 2, , "t", 2);
        if (exists("<curpath>\$first\$newName") == 2) { end true; }
        rename "l", "<curpath>\$first\$newName", , "<curpath>\$folder";
    }

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: move to sibling

Post by highend »

- my example in the first post also didn't mention any kind of "the first token"
- the task was described clearly (what to move and where to move, what to rename and how to rename)

absolutely different folder names should be taken into account when creating a code like this
The script did work on your example data. When the example (in other words: you) does not take possible cornercases into account, I need to do it?
do you have all your scripts created and ready right from the first attempt?
For my usage cases? I do. For others? Depends on how exact their sample data is...
this does not work:
Yeah, sure it doesn't...

$first = gettokenindex("<selitem>", "$folder", "<crlf>")

Missing semicolon. <selitem> should be found in a single folder name?
Even if it would be found, it would always return 1. Is that the correct index in the
list of items in the visible pane? Unlikely...

And even if that line would return the correct index number, the next line
overwrites it with the first part (separated by a space) of the folder?

Getting the name of the folder above the first selected item can be done like this:

Code: Select all

    $allItems = <get ItemsNames>;
    $indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
    $dst = gettoken($allItems, $indexDst, <crlf>);
And this was the last script fragment you can expect from me. Over and out
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 »

this also does not work (xyplorer shows no errors):

Code: Select all

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

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: move to sibling

Post by highend »

And why should that work?

the foreach(...) line is gone

Code: Select all

if (exists("<curpath>\$allItems") != 2) { continue; }
Aha, now the full list of all items in the pane is used for a command that checks the existence of a single file / folder?
And you're wondering why the return value is != 2?

$dst would contain the correct folder name
but instead of using that one, you're using $indexDst (a NUMBER!) as the "folder name" instead?
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 »

this code performs better:

Code: Select all

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

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

Re: move to sibling

Post by suslo »

Code: Select all

    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        $allItems = <get ItemsNames>;
        if (exists("<curpath>\$folder") != 2) { continue; }
        $indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
        $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";
    }
this variant moves+renames the 1st selected folder but the 2nd selected folder is moved to the last item in the list

'step mode' indicates that the problem (with the 2nd selected folder) is seemingly in line 6:
set
$indexDst
-1

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: move to sibling

Post by highend »

Because the whole destination folder stuff is only required once. So, does it belong into the loop?...
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

$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
in this line i tried to change 1 to 0 or to 2 or to c: or to c

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: move to sibling

Post by highend »

Read my last post again?
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

$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        $allItems = <get ItemsNames>;
        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";
    }
'step mode' indicates that this line:

Code: Select all

$dst = gettoken($allItems, $indexDst, <crlf>);
sets the destination folder to the last (not upper) item in navigation panel

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

Re: move to sibling

Post by highend »

Args...

Code: Select all

$indexDst = gettokenindex(gpc(<selitem>, "file"), $allItems, <crlf>, "i") - 1;
Was the $allItems variable filled with something before this line executes? No? So what will gettokenindex()
probably return? 0? Because the token was NOT found? What's 0 - 1? -1?

$dst = gettoken($allItems, $indexDst, <crlf>);
What will gettoken() return on a list of items with an index of -1? Maybe the last item in
that list?
One of my scripts helped you out? Please donate via Paypal

Post Reply