#1 2019-10-24 02:18

Rnmr
Member
Registered: 2019-10-22
Posts: 37

Rearrange a word order that targets a specific word(s) in a list...

How do you rearrange a word order that targets a specific word(s) in a list of files whose filenames vary in
length or number of words without using regular expressions, Pascal Script, etc.?

ex Filenames:

Happy fun time file.txt
File on toast.txt
Happy, Happy, Joy, Joy to the World.txt
Attack of the terrible vacation '05.txt

possible tasks:

Move the last word of every filename to the beginning
Move the first word of every filename to the end
Move the third word to the second position
...and so on

delimeter = single space

Filenames with an equal number of words are easy but
is the above example possible just using something like 'rearrange'
or combining just a 'few' of the preconstructed rules?



Regular Expressions and Pascal Script type solutions are welcome, but I view them as a last resort.

Last edited by Rnmr (2019-10-24 02:23)


To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.
- RWE

Offline

#2 2019-10-25 09:32

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rearrange a word order that targets a specific word(s) in a list...

Me think, Rearrange is not the tool for every purpose,
especially not for "filenames vary in length or number of words" AND counting from the end.

Maybe reading the help will aid you?
http://www.den4b.com/wiki/ReNamer:Rules:Rearrange

Rearrange rule works great for filenames with similar length, or if you want to count from left (from start) only.





You can try to utilize Rearrange rule, but based on filenames with different length you may not get the wanted result.

Move the last word of every filename to the beginning: try "$-1"
1) Rearrange: Split by delimiters " ", New pattern "$-1 $1 $2 $3 $4 $5 $6 $7 $8 $9" (skip extension)


Move the first word of every filename to the end: try "$1" at last element
1) Rearrange: Split by delimiters " ", New pattern "$2 $3 $4 $5 $6 $7 $8 $9 $1" (skip extension)


Move the third word to the second position: try "$1 $3 $2 $4"
1) Rearrange: Split by delimiters " ", New pattern "$1 $3 $2 $4 $5 $6 $7 $8 $9" (skip extension)




Some people rename there files in groups with same details, as for example filename length.


- - -


A Regular Expressions rule may work better
on filenames with different length AND working from the back (counting from the right side) :
http://www.den4b.com/wiki/ReNamer:Rules:RegEx


Move the last word of every filename to the beginning:
Exp: (.+) (.+)
Rep: $2 $1
(skip extension)
Explanation: (match everything greedy till LAST space and store in $1) (match everything till the end and store in $2)


Move the first word of every filename to the end:
Exp: (.+?) (.+)
Rep: $2 $1
(skip extension)
Explanation: (match everything non-greedy till FIRST space) (match everything till the end)


Move the third word to the second position:
Exp: (.+?) (.+?) (.+?) (.+)
Rep: $1 $3 $2 $4
(skip extension)
Explanation: (match everything non-greedy till FIRST space >$1)
(match everything non-greedy till SECOND space >$2) (match till THIRD space >$3) (match till the end >$4)




HTH? smile


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2019-10-25 22:07

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Rearrange a word order that targets a specific word(s) in a list...

If you use "Exact pattern of delimiters" option of the Rearrange rule, then it can work well with any number of words.

1. Move the last word of every filename to the beginning
> Split by exact pattern of delimiters " " (right-to-left), New pattern "$1 $2" (skip extension)

2. Move the first word of every filename to the end
> Split by exact pattern of delimiters " ", New pattern "$2 $1" (skip extension)

3. Move the third word to the second position
> Split by exact pattern of delimiters " ", " ", " ", New pattern "$1 $3 $2 $4" (skip extension)

Offline

#4 2019-10-27 23:04

Rnmr
Member
Registered: 2019-10-22
Posts: 37

Re: Rearrange a word order that targets a specific word(s) in a list...

Ok, thanks to both.

It looks like Stefan's RegEx is the winner.

the 'rule' situations could be somewhat helpful in certain situations but seems not all variations hold true.

Dennis' solution appears to only deal with the target words and leaves out all the other ones, unless, it was just a quick implied solution
that assumes I will further guess what else needs to be done/added.

Thanks again, I will play around some more. I think I have enough info to start mass building presets for my needs.


To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.
- RWE

Offline

#5 2019-10-28 13:28

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Rearrange a word order that targets a specific word(s) in a list...

Rnmr wrote:

Dennis' solution appears to only deal with the target words and leaves out all the other ones...

The Rearrange rule uses regular expressions under the bonnet, but with a goal to expose a more simplified set of options for rearranging parts of the filename. The Regular Expressions rule offers more features but at a cost of increased complexity.

The Rearrange rules mentioned previously will work with filenames containing any number of words. That is the benefit of the "Exact pattern of delimiters" option, versus the default "Delimiters" option.

For example, move the first word of every filename to the end:

renamer-move-first-word-to-the-ned.png

Offline

#6 2019-10-30 16:52

Rnmr
Member
Registered: 2019-10-22
Posts: 37

Re: Rearrange a word order that targets a specific word(s) in a list...

Ok Dennis, thanks!

I think I accidentally put in a wrong character or two (or, wrong pos.) when trying to recreate earlier on.
It seems to be working now.

Ok, so you are both the winner (in a field of two)! cool

den4b wrote:

The Rearrange rule uses regular expressions under the bonnet, but with a goal to expose a more simplified set of options for rearranging parts of the filename. The Regular Expressions rule offers more features but at a cost of increased complexity.

Yes, that was my understanding before your response.

Last edited by Rnmr (2019-10-30 17:23)


To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.
- RWE

Offline

#7 2019-11-01 13:37

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rearrange a word order that targets a specific word(s) in a list...

den4b wrote:

If you use "Exact pattern of delimiters" option ....

Good to know, will try to remember. Thanks for instructions. (please update the wiki with that example)




 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#8 2019-11-03 16:58

Rnmr
Member
Registered: 2019-10-22
Posts: 37

Re: Rearrange a word order that targets a specific word(s) in a list...

Well, things seemed to work on a quick, simple name re-test that I did, but I'm getting into it a little more
with some filename complexity and I can't get either of Stefan's or Denis' solutions to work properly.

I'm sure I'm doing something wrong, so try testing my new example below. Thanks!



Filename ex.,
VID Titlewrd1 Titlewrd2 [id1 id2 id3] _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3) [2019-10-07_20.01.30].mkv
VID Titlewrd1 Titlewrd2 [id1 id2 id3] _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3).mp4
VID Titlewrd1 Titlewrd2 [id1 id2 id3] _.mpg
VID Titlewrd1 Titlewrd2 id1 id2 id3 _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3) [2019-10-07_20.01.30].mp4
VID Titlewrd1 Titlewrd2 id1 id2 id3 _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3).avi

here is the switch:

I want words 4-6 to be before 2-3 (all other words included)

4 5 6 2 3

...working with a list of files that vary in length and not having to readjust the rule(s)
for every variation in the list.

Last edited by Rnmr (2019-11-03 23:37)


To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.
- RWE

Offline

#9 2019-11-04 15:41

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Rearrange a word order that targets a specific word(s) in a list...

The following configuration of the Rearrange rule will work on your examples:

Split using: Exact pattern of delimiters
Delimiters: " | | | | | "
New pattern: "$1 $4 $5 $6 $2 $3 $7"

(exclude the quotation marks)

Input files:

VID Titlewrd1 Titlewrd2 [id1 id2 id3] _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3) [2019-10-07_20.01.30].mkv
VID Titlewrd1 Titlewrd2 [id1 id2 id3] _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3).mp4
VID Titlewrd1 Titlewrd2 [id1 id2 id3] _.mpg
VID Titlewrd1 Titlewrd2 id1 id2 id3 _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3) [2019-10-07_20.01.30].mp4
VID Titlewrd1 Titlewrd2 id1 id2 id3 _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3).avi

Output:

VID [id1 id2 id3] Titlewrd1 Titlewrd2 _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3) [2019-10-07_20.01.30].mkv
VID [id1 id2 id3] Titlewrd1 Titlewrd2 _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3).mp4
VID [id1 id2 id3] Titlewrd1 Titlewrd2 _.mpg
VID id1 id2 id3 Titlewrd1 Titlewrd2 _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3) [2019-10-07_20.01.30].mp4
VID id1 id2 id3 Titlewrd1 Titlewrd2 _ (kwrd1, kwrd2, kwrd3 - act1, act2, act3).avi

Offline

#10 2019-11-07 00:32

Rnmr
Member
Registered: 2019-10-22
Posts: 37

Re: Rearrange a word order that targets a specific word(s) in a list...

Okay, your solution to the examples I give you work.
But, your not 'telling' me the logic of how it works.
You are just showing it.

When I change the pattern to something different for a new problem, it does not work because I
don't understand what the exact logic is.

Yes, I might have been able to figure that out just from the example but not necessarily.
You gotta know that there are plenty of people out there that aren't going to
be able to do that.

So, you do both. You "show" the logic and you tell/state the logic for 'anyone'
that might be reading the topic.

Yes, I know some issues are a little more complex and time consuming to state out, but can you at least try?

For ex., here is something that I see in the solution to my previous examples:


Observation #1- There are 5 words, as defined by 'exact delimeters' (but 6 spaces surrounding), directly involved in
                         the rearrangement '$4 $5 $6 $2 $3'
Observation #2- The $1 and $7 are not 'directly' part of the order change.
Observation #3- The shortest example length is 7 words, defined by the 'exact delimeters' (6 spaces)
                         'VID Titlewrd1 Titlewrd2 [id1 id2 id3] _.mpg'.

So one conclusion could be:

For the amount of words one is rearranging, you create the 'same number of
delimeters + 1 (6 single spaces)'

...and similar for the words in the 'new pattern' notation (word numbers, then add parameters $1 at beg + the
next highest # in the sequence" at the end)

...therefore, if '$4 $8 $3 $6 $2', then add $1 and $9 as parameters for '$1 $4 $8 $3 $6 $2 $9' ?


I know that logic is flawed (it certainly does not work), but that is what I mean by if the logic could be written/explained out
in some way without necessarily going into too much of the detailed minutiae of how RegEx works.

Thanks for your time & patience wink

Last edited by Rnmr (2019-11-07 00:33)


To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment.
- RWE

Offline

Board footer

Powered by FluxBB