Difference between revisions of "ReNamer:Rules:Rearrange Examples"

From den4b Wiki
Jump to navigation Jump to search
m (Reverted edits by Stefan (talk) to last revision by Den4b)
Tag: Rollback
 
Line 700: Line 700:
  
 
1. All files having the same ''number'' will be sorted into a common subfolder. <br>2. ReNamer will create these subfolders in the current folder<br>3. The "Part " is a literal string. (note the space at the end) <br>  
 
1. All files having the same ''number'' will be sorted into a common subfolder. <br>2. ReNamer will create these subfolders in the current folder<br>3. The "Part " is a literal string. (note the space at the end) <br>  
 
 
== Split by positions ==
 
 
=== Example 1  ===
 
<PRE>
 
FROM:
 
FECAAFC2309C055D7E7D61C4C669F9C0.dat
 
That is:
 
0  1  2  3  4  5  6  7  8 9101112131415
 
FE CA AF C2 30 9C 05 5D 7E7D61C4C669F9C0
 
 
TO: 
 
C2AFCAFE9C305D057E7D61C4C669F9C0.dat
 
That is:
 
3  2  1  0  5  4  7  6  8 9101112131415
 
C2 AF CA FE 9C 30 5D 05 7E7D61C4C669F9C0
 
</PRE>
 
USE: 
 
Rearrange rule:  <BR>
 
If you enter position n, ReNamer will chop the n-th character and all characters beyond that in a separate piece.  <BR>
 
Split by positions: 3|5|7|9|11|13|15|17  <BR>
 
New pattern: $4$3$2$1$6$5$8$7$9  <BR>
 
Skip extension: YES  <BR>
 
 
=== Example 2  ===
 
 
<BR>
 
 
FROM:<BR>
 
ABCDEFGHI<BR>
 
 
TO:<BR>
 
AB<BR>
 
 
Split by positions: 3 <BR>
 
New pattern: $1  <BR>
 
 
Explanation:<BR>
 
3 = Store everything before position 3 in variable $1 <BR>
 
 
- - -
 
 
FROM:<BR>
 
ABCDEFGHI<BR>
 
 
TO:<BR>
 
AB-AB-AB<BR>
 
 
Split by positions: 3 <BR>
 
New pattern: $1-$1-$1 <BR>
 
3 = Store everything before position 3 in variable $1 <BR>
 
 
- - -
 
 
FROM:<BR>
 
ABCDEFGHI<BR>
 
 
TO:<BR>
 
AB - CD (EFGHI)<BR>
 
 
Split by positions: 3|5 <BR>
 
New pattern: $1 - $2 ($3) <BR>
 
 
Explanation:<BR>
 
3 = Store everything before position 3 in variable $1 <BR>
 
5 = Everything starting at pos. 3 till before pos. 5 in variable $2 <BR>
 
Store the rest (silently) in $3 <BR>
 
AB CD EFGHI <BR>
 
12 34 56789 <BR>
 
 
- - -
 
 
FROM:<BR>
 
ABCDEFGHI<BR>
 
 
TO:<BR>
 
ABC - DEF - GHI<BR>
 
 
Split by positions: 4|7|10<BR>
 
New pattern: $1-$2-$3<BR>
 
 
Explanation: <BR>
 
4 = Store everything before position 4 in variable $1 <BR>
 
7 = Everything starting at the last position (4) till before pos. 7 in variable $2 <BR>
 
Everything starting at pos. 10 till the end in variable $3  (that ReNamer would do for us too) <BR>
 
ABC DEF GHI <BR>
 
123 456 789 <BR>
 
 
- - -
 
 
FROM:<BR>
 
ABCDEFGHI<BR>
 
 
TO:<BR>
 
ABCD GHI<BR>
 
 
Split by positions: 5|7|555<BR>
 
New pattern: $1 $3<BR>
 
 
Explanation: <BR>
 
5 = Store everything before position 5 in variable $1 <BR>
 
7 = Everything starting at pos. 5 till before pos. 7 in variable $2 <BR>
 
555 = Everything starting at the last position till the end in variable $3 <BR>
 
Please note that we have dropped var '$2' in the 'New pattern'. <BR>
 
ABCD EF GHI <BR>
 
1234 56 789 <BR>
 
 
- - -
 
 
FROM:<BR>
 
ABCDEFGHI<BR>
 
 
TO:<BR>
 
GHI (EF) A BC D<BR>
 
 
Split by positions: 2|4|5|7|999<BR>
 
New pattern: $5 ($4) $1 $2 $3<BR>
 
 
Explanation: <BR>
 
2 = Store everything before position 2 in variable $1 <BR>
 
4 = Everything starting at the last position (2) till before pos. 4 in variable $2 <BR>
 
5 = Everything starting at the last position pos. till pos.5 in $3 <BR>
 
7 = Everything starting at the last position pos. till pos.7 in $4 <BR>
 
999 = Everything starting at the last position till the end in variable $5 <BR>
 
Please note that we have rearranged (switched) the output vars in the 'New pattern'. <BR>
 
A BC D EF GHI <BR>
 
1 23 4 56 789 <BR>
 
 
 
 
 
 
 
 
 
 
  
 
<br>
 
<br>
 
[[Category:ReNamer]]
 
[[Category:ReNamer]]

Latest revision as of 22:42, 8 July 2019

Rearrange rule can be used in many ways. Few examples are given below.

For simplicity's sake, we have split examples into two sections: Basic usage (typical needs of beginners) and Advanced usage (for the power users).

Basic usage

Example 1

Task: Swap parts of name.

From: To:
Artist - Title.mp3 Title - Artist.mp3

Settings:

Split using: (o)Delimiter
" - " (without the quotes)

New pattern: $2 - $1
[X] Skip Extensions

Explanation: We split the string at the hyphen (dash or minus sign -) or whatever you use to separate Artist from Title
Now, all signs before the dash are stored in variable $1, all after are put in var $2.
Because we want to swap this parts, we simple swap the vars in the output, the "New Pattern": $2 $1
And since this rule removes the used delimiter, we add it on our own: "$2 - $1", or use an new delimiter as e.g.: "$2_-_$1"

Example 2

Task: Insert text before the original name.

From: To:
Ring Ring
ABBA - Ring Ring
The winner takes it all
ABBA -The winner takes it all

Settings:

Delimiter: none (leave blank)

New order/pattern: ABBA - $0

Remarks:  is same as the Insert rule.

Example 3

Task: Insert text before and after the original name.

From: To:
Ring Ring
ABBA- Ring Ring (Live)
The winner takes it all
ABBA-The winner takes it all (Live)

Settings:

Delimiter: none (leave blank)

New order/pattern: ABBA- $0 (Live)

Remarks: is same as using the Insert rule twice (one for adding the prefix, and another for adding the suffix).

Example 4

Task: Switch the words, and remove the comma between them.

From: To:
King, Stephen Stephen King
Cook, Robin Robin Cook
Pride and Prejudice, The The Pride and Prejudice

Settings:

Delimiter: ", " (without the quotes)

New Order: $2 $1

Example 5

Task: Move a word to a new position.

From: To:
Words sample 1234 07-07-07 1234 Words sample 07-07-07

Settings:

Delimiter: " " (only a space, without the quotes)

New Order: $3 $1 $2 $4

Example 6

Task: Get rid of the numbers, hyphen and space at the beginning.

From: To:
01 - Afilename.zip Afilename.zip
002 - Bfilename.zip Bfilename.zip
0003 - Cfilename.zip Cfilename.zip

Settings:

Delimiter: "- " (without the quotes)

New Order: $2

Remarks:

  1. Note that the delimiter contains a space. If only a hyphen is used as delimiter, then a space would be left out in the beginning of the name, which you would have to trim separately.
  2. The Delete rule also would work (in right-to-left mode). But the Rearrange rule also allows you to add any string to the truncated names.

Example 7

Task: Move the first part to the end.

From: To:
TEST.aaa.bbb.100.ext aaa.bbb.100.TEST.ext

Setting:

Delimiter: "." (without the quotes)

New Order: $2.$3.$4.$1

Example 8

Task: Move the artist's name from end to the beginning, and change the name format.

From: To:
Ring ring_ABBA.mp3 ABBA - Ring Ring.mp3
Material girl_Madonna.mp3 Madonna - Material girl mp3

Settings:

Delimiter: "_" (without the quotes)

New Order: $2 - $1

Example 9

Task: Move the numbers to the beginning.

From: To:
DSC_0001-1.jpg 1-DSC_0001.jpg
DSC_0001-2.jpg 2-DSC_0001.jpg
DSC_0001-10.jpg 10-DSC_0001.jpg

Settings:

Delimiter: "-" (without the quotes)

New Order: $2-$1

Example 10

Task: Insert "sent_" before the last 3 digits.

From: To:
family_001.jpg family_sent_001.jpg
work_023.jpg work_sent_023.jpg
friend_098.jpg friend_sent_098.jpg

Settings:

Delimiter: "_" (without the quotes)

New Order: $1_sent_$2

Remarks:

The Insert rule also would work (in right-to-left mode). But the Rearrange rule also allows you to add any string to the names.

Example 11

Task: Remove the name of the artist (delete text until hyphen).

From: To:
Sting - All This Time.mp3 All This Time.mp3

Settings:

Delimiter: "- " (without the quotes)

New Order: $2

Remarks:

  1. Note the space after the hyphen. If we use just a "-" as delimiter, the second token would be left with a space in front, which we will have to trim separately.
  2. Even the Delete rule would have worked (in right-to-left mode). But the Rearrange rule also allows you to add any string to the new name.

Example 12

Task: Remove the track numbers (and any separator symbol after that) from the beginning of the filenames:

From: To:
08. Madonna - Like A Prayer.wma Madonna - Like A Prayer.wma
08.-Madonna - Like A Prayer.wma
08 Madonna - Like A Prayer.wma

Settings:

Delimiter: "Madonna" (without the quotes)

New Order: Madonna$2

Remarks:

We chose the string "Madonna" as delimiter because it does not occur anywhere else in the names. The unwanted characters on the left are assigned to token $1, which we will not omit in the new name. However, there is an undesired side-effect: ReNamer removes "Madonna" string from the token $2 because it is the delimiter. Therefore, we have to manually add that missing string "Madonna" to $2, to restore the names.

Example 13

Task: Move the number to front, and remove the square brackets.

From: To:
Name XXX [0001].jpg 0001 - Name XXX.jpg

Settings:

Delimiter: " [|]" (without the quotes)

New Order: $2 - $1

Remarks:

  1. The "|" (vertical pipe) character is used to separate the two delimiters.
  2. The second delimiter "]" will not produce a token. It is included only to remove it from the new name.

Example 14

Task: Add composer name and duration to an mp3 file, as prefix and suffix, respectively.

From: To:
Eine kleine Nachtmusik.mp3 Mozart - Eine kleine Nachtmusik (6.37).mp3
Don Giovanni.mp3 Mozart - Don Giovanni (4.5).mp3

Settings:

Positions: 1

New Order: Mozart - $2 (:Audio_Duration:)

Remarks:

  1. This can also be done by using the Insert rule. However, you have to use that rule twice (once for prefix and the second time for the suffix). On the other hand, the Rearrange rule allows you to add both in a single stroke. Besides, you can see the structure of the new name.
  2. When the original name is sliced at position 1, there is no characters on the left side; so the $1 token is a blank. The entire name is copied into the $2 token. This is a great trick to compose new name using the whole original name.

Example 15

Task: Swap parts of name at fixed position.

From: To:
BusinessRawReport1.doc
RawReport1, Business.doc
BusinessRawReport2.doc
RawReport2, Business.doc
BusinessRawReport3.doc
RawReport3, Business.doc

Settings:

Split using: (o)Positions
"9" (without the quotes)

New pattern: $2, $1
[X] Skip Extensions

Remarks: Since we didn't have an real delimiter here, we simply split at an position within the string, here e.g. at char number 9:
BusinessRawReport1.doc
123456789

So all before 9th char is put in variable $1, and all from char number 9 till end of string is put in var $2.
That means: $1 holds 'Business' and $2 holds 'RawReport1'. (Note that we skip the extension, so we don't have to deal with it)
Now we compose our new string, the output pattern, just as we like it to be: '$2, $1'

-

You can also use more then one delimiter or position:

From: To:
BusinessRawReport1.doc
Raw Business Report1.doc

Settings:

Split using: (o)Positions
"9|12" (without the quotes)

New pattern: $2 $1 $3
[X] Skip Extensions

Remarks:

BusinessRawReport1.doc
123456789
123456789012

$1 holds 'Business'
$2 holds 'Raw'
$3 holds 'Report1'

Advanced usage

Example 1

Task: Remove the string from the file name.

From: To:
Artist - Title [Time 4 02 Cold] [2004].mpg Artist - Title [2004].mpg

Settings:

Delimiter: " [T|d] " (without the quotes)

New Order: $1 $3

Remarks:

  1. The | character separates the two delimiters.
  2. Notice that we have included spaces in the delimiters, so that they do not end up as part of the tokens.
  3. We have selected two different delimiters to represent the beginning and the end of the string we want to remove. Thus whatever lies between the two delimiters is converted into a token. This token is then omitted in the new name. This works just like using wildcards for the string (or a RegEx pattern).

Example 2

Task: The file names contain artist name, album name and track name. Sort them into separate folders as follows:

  1. Create a separate folder for each artist.
  2. For each artist, create a subfolder for each album.
  3. Move each file in the corresponding folder.
From: To:
Title - Artist (Album).mp3 D:\Artist\Album\Title.mp3

Settings:

Delimiter: " - | (|)" (without the quotes)

New pattern: D:\$2\$3\$1

Remarks:

  1. Note that the delimiters contain spaces and symbols, so that only text remains in the tokens.
  2. The last delimiter ) does not produce a token. It is added just to strip the closing bracket from the last token.
  3. Instead of D: a relative path (such as ..\..\) can be added to the front.

Example 3

Task: Sort digital photos in different folders based on the Date taken for each photo.

Note: Many people call this operation "binning", because we segregate the items into separate bins based on some criteria. (most people associate the word "Sorting" with "rearranging the files in ascending/descending order, without moving them to other folders")


From: To:
DSC_0001.jpg D:\photos\trip\2009_10_21\DSC_0001.jpg
DSC_0002.jpg D:\photos\trip\2009_10_21\DSC_0002.jpg
DSC_0003.jpg D:\photos\trip\2009_10_25\DSC_0003.jpg

Settings:

Delimiter: - (none)

New pattern: D:\photos\trip\:EXIF_Date:\$0

Remarks:

  1. Note that this EXIF data is contained in the meta tag of each photo, not in the file name.
  2. The meta tag :EXIF_Date: is replaced by the actual date taken for each photo. Thus all photos taken on the same date will be moved to the same folder.
  3. The actual name of the folder would depend on the Date and Time format settings.

Example 4

Task: Delete the last part of the base name (but the extension should remain). Note that the file names have different lengths, so you cannot slice the name at a particular position. The names have a different depths also (number of segments separated by dots).

From: To:
title.text1.text2.extension title.text1.extension
title.text1.text2.text3.extension title.text1.text2.extension

Setting: The solution requires a stack of two different rules, as shown below:

1. Replace Rule

Find: "." (without the quotes)

Replace: "#" (without the quotes)

Check "[X] Last" to find and replace last occurrence of an dot only.
Check "[X] Skip Extension" to not replace the file/extension separator as last dot.

(this is a temporary change; which will be eliminated in the second step)

2. Rearrange rule

Delimiter: "#" (without the quotes)

New Order: $1

Remarks:

We had to do this indirectly because the Rearrange rule cannot pick only the last dot as delimiter; and ignore the other dots. So we used a trick: we first changed the last dot into another character (using the Replace rule), and then use that new character as delimiter in the Rearrange rule.


Example 5

Task: Swap parts with more then one of the same delimiter

From: To:
I. Author - Book title - True story.pdf Book title - True story (I. Author).pdf
I. Author - Book title.pdf Book title (I. Author).pdf

First exchange the first occurrence of the delimiter by an completely other sign, e.g. #

  • Add an "Replace" Rule
  • Replace First " - " with "#", [X] Skip Extension

So we got

From: To:
I. Author # Book title - True story.pdf Book title - True story (I. Author).pdf
I. Author # Book title.pdf Book title (I. Author).pdf


Now use Settings:

Split using: (o)Delimiter
" # " (without the quotes)

New pattern: $2 ($1)
[X] Skip Extensions

Remarks: Since this rule removes the used delimiter, we don't have to take care about them in the output.


Example 6

Task: Keep only the last part of a file name:

From: To:
title text1 text2.txt text2.txt
title text1 text2 text3.txt text3.txt

Settings:

Split using: (o)Delimiter
" " (space, without the quotes)

New pattern: $-1
[X] Skip Extensions

Task: Keep only the second last part of a file name:

From: To:
title text1 text2.txt text1.txt
title text1 text2 text3.txt text2.txt

Settings:

Split using: (o)Delimiter
" " (space, without the quotes)

New pattern: $-2
[X] Skip Extensions

Remarks: Since $-1 and $-2 count the tokens from the right (from the end), we will get the same result even if the name is longer.

Example 7

Task: Sort files with same names (but different extensions) into separate subfolder.
           Typically, training websites provide such sets of files for each episode/lecture/lesson, etc. (video, handout, homework, etc.)
            When you download these files, they are in a single folder. ReNamer helps you in sorting them into separate folders.

We will see two different variations here:

Variation-1: The subfolder name is same as the base name of the files.

From: To:

Episode 001.pdf
Episode 001.mp4

Episode 002.pdf
Episode 002.mp4

Episode 001\Episode 001.pdf
Episode 001\Episode 001.mp4

Episode 002\Episode 002.pdf
Episode 002\Episode 002.mp4

Settings:

 Split using: - (Leave blank)
 New pattern: $0\$0
 [X] Skip Extensions

Remarks:

1. All files having the same base name will be sorted into a common subfolder.
2. ReNamer will create these subfolders in the current folder.


Variation-2: The subfolder name is different as compared to the base name of the files.

From: To:

Handout 001.pdf
Lesson 001.mp4

Handout 002.pdf
Lesson 002.mp4

Part 001\Handout.pdf
Part 001\Lesson.mp4

Part 002\Handout.pdf
Part 002\Lesson.mp4

Settings:

 Split using:" " (space, without the quotes)
 New pattern: Part $2\$1
 [X] Skip Extensions

Remarks:

1. All files having the same number will be sorted into a common subfolder.
2. ReNamer will create these subfolders in the current folder
3. The "Part " is a literal string. (note the space at the end)