move to sibling

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

move to sibling

Post by suslo »

for example, there are 14 folders:
band01
band06
band06 - 2005 - album02
band07
band10 - 2000 - album01
band11
band20
band20 - 2010 - album02
band20 - 2011 - album03

band21
band28
band34 - 1995 - album01
band34 - 2010 - album02
band44
2 folders are selected:
band20 - 2010 - album02
band20 - 2011 - album03

how to move these 2 selected folders to the upper next sibling folder? i mean to the band20 folder

after the movement: the folders (which were selected and then moved) have to be renamed according to these 2 rules:
new name should not have the characters before the 1st occurrence of these 3 characters: " - "
new name should not have the 1st occurrence of these 3 characters: " - "

after rename the result is:
band20 - 2010 - album02
becomes:
2010 - album02
band20 - 2011 - album03
becomes:
2011 - album03
in case of name collision: the automatic overwriting should not happen

i tried some variants including:
moveas "*.?", "<curitemprev>"
moveto "<curpathprev>"
but as i eventually understood, the necessary variable does not exist so some different approach is needed

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

Re: move to sibling

Post by highend »

Loop over selected, get the first part of the folder name via gettoken(), move them, rename them afterwards according to your rules (or rename in list mode to save one step)?
One of my scripts helped you out? Please donate via Paypal

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

Re: move to sibling

Post by suslo »

Loop over selected
what does it mean?
gettoken()
Returns a substring by index
gettoken(string, [index=1], [separator=" "], [format], [flags])
string (not changed by procedure): i don't know which symbols will be kept (everytime the folder names will be almost completely different)
something else will always be instead of "band20"
something else will almost always be instead of "2010"
something else will always be instead of "album02"
even the quantity of " - " could be different (usually 2 but sometimes not 2)

index (Index of token): what should i type here?

separator (separator of tokens): are these 3 symbols " - " correct?

format (Switches for the desired formatting): should i leave it empty?

flags (bit field): should i use "1" here?
move them
how?

at the moment i only have this:
gettoken("", , " - ", , 1)
which is nothing. so i ask for the help

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

Re: move to sibling

Post by highend »

what does it mean?
That you need to loop over the selected folders?
how?
E.g. via moveto but rename() in list mode would also work
gettoken("", , " - ", , 1)
Em...

Code: Select all

    $a = "band20 - 2010 - album02";
    // Get the new destination folder name (use <curpath> to make it a full path...)
    $b = gettoken($a, 1, " - ", "t");
    // New name of the subfolder (without path)...
    $c = gettoken($a, 2, " - ", "t", 2);
    text "_" . $b . "_";
    text "_" . $c . "_";
One of my scripts helped you out? Please donate via Paypal

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

Re: move to sibling

Post by suslo »

you need to loop over the selected folders
what is "loop over"? how to perform this "loop over"?
via moveto
these variants do not work:
moveto "<curpathprev>"
moveto "<curitemprev>"
what is the variable for "previous sibling folder which is present right above the currently selected folders"?
$a = "band20 - 2010 - album02";
how can this line be used in the script in real conditions?

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

Re: move to sibling

Post by highend »

what is "loop over"?

Code: Select all

help "idh_scripting.htm#idh_scripting_foreachloops";
what is the variable for "previous sibling folder which is present right above the currently selected folders"?
There is no variable? A lot of ways are possible to get a folder name above the first selected item in a list pane but why don't
you just use the first part of the folder names in your example via gettoken()???
how can this line be used in the script in real conditions?
It wasn't posted to be used in a "real" script, it was used to show how you get the necessary parts of one of your folders to be moved (to generate the correct name in it's new subfolder)

@jupe
If you want, post it. But I guess you know my opinion :mrgreen:
One of my scripts helped you out? Please donate via Paypal

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

Re: move to sibling

Post by suslo »

i would like to know your opinion
so that i knew what i'm doing wrong. i'm trying to describe the task in all possible details, i'm trying to find the ways to solve it before posting here, i realize the complete lack of scripting knowledge and that's why i have to ask questions

the questions which are seemingly very primitive from time to time
but it's because i want the have the result, i don't want to spend your time and my time this way but it's your choice to constantly give such short and not clear answers

not clear for a person who knows 100 times less than you. can you imagine this difference?
how do you think many of your clever lines (not a sarcasm) look like to a person who only began to understand something in scripting?

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

Re: move to sibling

Post by highend »

i'm trying to describe the task in all possible details
Mh, let's say mostly. Why do I say that? Because sometimes later in the thread you say things like:
even the quantity of " - " could be different (usually 2 but sometimes not 2)
Great. And would that change how the script should work? I don't know and you didn't explain
how or if you'd need a different way to get the first part of a folder name or not.
Apart from that: I appreciate it that you're trying to explain it and deliver a real world example...
but it's because i want the have the result, i don't want to spend your time and my time this way but it's your choice to constantly give such short and not clear answers
Yeah, it's my choice, you're absolutely right. And I know that there are people out there that don't like this way. But...
This is not the first time you're asking scripting questions and that's ok.
But sorry, how many examples for (your) script help topics have already dealt with loops? Seriously.
So is it really too hard to look up loops in the help file after somebody (let's say: me) mentioned that you need one?
The most basic script that probably does what you're trying to achieve is:

Code: Select all

    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        if (exists("<curpath>\$folder") != 2) { continue; }
        $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";
    }
The exists() statements make sure that
- No file is moved (only selected folders)
- If the destination folder does not exists, do not contine
- If the destination subfolder already exists, do not continue

So in the end this is nothing more than a loop with a gettoken() and a move / rename command
The rest is just for making sure that some non-wanted things happen
As far as I'm concerned my answers on your questions contained all this stuff before (a loop, gettoken(), moveto / rename in list mode)...
One of my scripts helped you out? Please donate via Paypal

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

Re: move to sibling

Post by suslo »

And would that change how the script should work?
if that could change the way the script should work, i would have mentioned that
instead, in the very beginning i've mentioned twice (both in bold): "the 1st occurrence"
which automatically means that you simply don't have to care about all other occurrencies (whether they exist or not)
if you'd need a different way to get the first part of a folder name
should i have to think about the way? while you (with your knowledge) seemingly know the most appropriate way immediately after you've read the task
so if i don't say anything about such ways, then it means that: i don't really know which ways exist; i don't really care which way will be used (as long as this way does the job and does it better than other ways could do)
how many examples for script help topics have already dealt with loops?
in recent hours i failed to recollect the "foreach"
anyway, i can only recollect that you don't like to use it. that's my impression, i may be wrong
in other words: "loop over" gave me no association to "foreach"
but that's ok since it's too complicated for me anyway
most basic script
2 such sub-windows appear when trying to execute the script:
rename failed
an item could not be renamed
The following item could not be renamed:
C:\(Temporary)\del2\band20 - 2010 - album02
Error: The filename, directory name, or volume label syntax is incorrect.
The rename job is now completed. 0 of 1 item have been renamed
If the destination folder does not exists, do not contine
the destination folder will never be absent because i will always see it right above the selected folders which are about to be moved
If the destination subfolder already exists, do not continue
is this the safety belt in case of name collision?

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

Re: move to sibling

Post by highend »

should i have to think about the way?
You should. It's your script. Make it efficient. The whole thing can't be done e.g. via a regex and without a loop because of the restriction that if the subfolder already exists, the original folder shouldn't be moved
2 such sub-windows appear when trying to execute the script
If you talk about "windows", show screenshots. Apart from that, put a step;
command above the rename ... line and look up how the rename will resolve
all the parameters it's been given. If in doubt about why it doesn't work, screenshot...
the destination folder will never be absent
Then remove the corresponding exists() line
is this the safety belt in case of name collision?
Exactly
One of my scripts helped you out? Please donate via Paypal

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

Re: move to sibling

Post by suslo »

show screenshots
there 2 of them (without a step; command) and 15 more (with it)
the 1st 2 will give you nothing new but you say "show" so:
1.PNG
2.PNG
3.PNG
4.PNG
5.PNG
6.PNG
7.PNG
8.PNG
9.PNG
10.PNG
11.PNG
12.PNG
13.PNG
14.PNG
15.PNG
16.PNG
17.PNG
To see the attached files, you need to log into the forum.

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

Re: move to sibling

Post by highend »

Configuration | General | Sort and Rename | Rename | [x] Allow move on rename

Needs to be enabled for the rename ... command to work this way
One of my scripts helped you out? Please donate via Paypal

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

Re: move to sibling

Post by highend »

@Don

Is it really a necessity that the rename command needs the gui setting to work that way?
It would be nice if it wouldn't depend on it...
One of my scripts helped you out? Please donate via Paypal

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

Re: move to sibling

Post by suslo »

"Allow move on rename" solved the problem, thank you for the help

so this is the working script:

Code: Select all

    foreach($folder, <get SelectedItemsNames <crlf>>, <crlf>, "e") {
        if (exists("<curpath>\$folder") != 2) { continue; }
        $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";
    }
why the exclamation mark is present in line 2?
in the help: the exists() command has the 'return' part of syntax where '2' means 'folder exists'
so this line 2 means to me: if the selected items are not folders, then continue


for example, it's necessary to perform just the movement of folders/files (without rename)
the following code only works partially (mostly it is not working)
i tried many times to alter your script but i even cannot understand what is wrong with this variant:

Code: Select all

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

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

Re: move to sibling

Post by highend »

if the selected items are not folders, then continue
Yeah, and? Your example contains folders that need to be moved into subfolders -> The script will only process folders with that line
for example, it's necessary to perform just the movement of folders/files (without rename)
Step (step; command!) through the script, at which line does it fail?
E.g.

Code: Select all

$newName = gettoken($folder, 2, , , 2);
Ok, now all parts of a file folder are separated via a single space?
Where is the real world example in this case?
Without any real data, how should I know why it doesn't work???
One of my scripts helped you out? Please donate via Paypal

Post Reply