Batch rename with parts of path

Discussion of bugs and problems found in Altap Salamander. In your reports, please be as descriptive as possible, and report one incident per report. Do not post crash reports here, send us the generated bug report by email instead, please.
magger
Posts: 3
Joined: 05 Jul 2008, 18:47

Batch rename with parts of path

Post by magger »

Hi,
my problem is:
I have one folder "top" with ~ 6000 subfolders.
Every subfolder has a name like "xxxabcxxx" with always the same "x"
and different "abc" parts.
In every subfolder there is only one file named "123.jpg" and ~ 200 other files.

So we have 6000 files like "top/xxxabcxxx/123.jpg" with different abc-parts.

Now I want all 6000 "123.jpg" files to be renamed to "abc.jpg", taking the abc-part from its path - and then move all renamed files to the top folder.

I tried, but found no way to put a part of the path string into the "rename to" field.
Any ideas? :?

thx in adv.
m
User avatar
SelfMan
Posts: 1155
Joined: 05 Apr 2006, 20:51
Contact:

Post by SelfMan »

You have to use regular expressions.
Something like: xxx([a-z]+)xxx
The content of () will be placed in $(0).
Jan Rysavy
ALTAP Staff
ALTAP Staff
Posts: 5231
Joined: 08 Dec 2005, 06:34
Location: Novy Bor, Czech Republic
Contact:

Post by Jan Rysavy »

There is only one ???.jpg file in each directory? The name ??? is same through all directories?

Regarding xxxabcxxx: the "abc" sub-string is always three letters long and begins on fourth character? Does it contain only alpha characters ('a'..'z')?
magger
Posts: 3
Joined: 05 Jul 2008, 18:47

Post by magger »

In each directory there are ~ 200 different jpg files and one ???.jpg and yes, the name ??? is the same through all directories.

Regarding xxxabcxxx folder names: the abc string is three to seven letters long, contains numbers, alpha characters (lower & upper) and underscores. But it always starts on ninth position.

Examples:
from
AAA-AAA_a_1_AAAAA
to
AAA-AAA_ZZZ_999_AAAAA

The blue parts are always the same

So the ???.jpg should become a_1.jpg in example 1 and ZZZ_999.jpg in example 2.
Jan Rysavy
ALTAP Staff
ALTAP Staff
Posts: 5231
Joined: 08 Dec 2005, 06:34
Location: Novy Bor, Czech Republic
Contact:

Post by Jan Rysavy »

magger wrote:...the abc string is three to seven letters long...

Examples:
from
AAA-AAA_a_1_AAAAA
to
AAA-AAA_ZZZ_999_AAAAA

The blue parts are always the same
I don't see how to select the "abc" sub-string when the length differs.
Is it always in format CHARACTERS_NUMBERS, for example a_1, AX_22, CAC_999, etc? The CHARACTERS sub-string does contain only characters (lower/upper case) and the NUMBERS sub-string does contain only numbers? The minimal length of both CHARACTERS and NUMBERS sub-strings is one and maximal is 3?

You are talking about "underscores", so there could be more underscore characters?

Is the "abc" sub-string always separated by underscore characters?

Is the ending sub-string (_AAAAA in you examples) always fixed length?

We need really exact information here...
magger
Posts: 3
Joined: 05 Jul 2008, 18:47

Post by magger »

Is it always in format CHARACTERS_NUMBERS, for example a_1, AX_22, CAC_999, etc? The CHARACTERS sub-string does contain only characters (lower/upper case) and the NUMBERS sub-string does contain only numbers? The minimal length of both CHARACTERS and NUMBERS sub-strings is one and maximal is 3?
Yes, exactly
You are talking about "underscores", so there could be more underscore characters?
No, sorry, only one underscore in the middle.
Is the ending sub-string (_AAAAA in you examples) always fixed length?
Yes, always the same. I think it would be to erase all the _AAAAA endings from the folder names as a first step. I don't really need them.
Jan Rysavy
ALTAP Staff
ALTAP Staff
Posts: 5231
Joined: 08 Dec 2005, 06:34
Location: Novy Bor, Czech Republic
Contact:

Post by Jan Rysavy »

Salamander window:
Open the 'top' directory and select all sub directories you want.
From the Plugins menu choose the Rename > Batch Rename command.

Renamer window:
In the Options menu turn on "Rename Relative Path" option.
Then set all options according to the attached screenshot.

Before you click the Rename button, check the Preview. Also some temporary backup of the whole top directory would be good idea.
Note: in the Commands menu you can find the Undo command.

Edit: another three "Search for" versions:

Code: Select all

.*?_(.*)_.*\\.*

[^_]*_(.*)_[^_]*\\.*

......._(.*)_.*
See Regular Expressions Help.
Attachments
renamer.png
renamer.png (28.56 KiB) Viewed 15754 times
Jan Rysavy
ALTAP Staff
ALTAP Staff
Posts: 5231
Joined: 08 Dec 2005, 06:34
Location: Novy Bor, Czech Republic
Contact:

Post by Jan Rysavy »

Does it work for you? Please let us know...
User avatar
Stefan
Posts: 46
Joined: 18 Jan 2006, 12:48

Post by Stefan »

magger wrote:the abc string [...] But it always starts on ninth position.

Q: Is the ending sub-string (_AAAAA in you examples) always fixed length?
A: Yes, always the same.

Examples:
from
AAA-AAA_a_1_AAAAA
to
AAA-AAA_ZZZ_999_AAAAA

The blue parts are always the same

So i would try this RegEx: .{7}_(.+)_.{5}\....
Stefan
Pleased user since v1.52        -   Licence# 0306-0046-01
User avatar
Ether
Posts: 1471
Joined: 10 May 2007, 16:08
Location: Czech Republic
Contact:

Post by Ether »

Stefan wrote:So i would try this RegEx: .{7}_(.+)_.{5}\....
Salamander's implementation doesn't support precise quantificators, i.e. {n}.
Ελληνικά rulez.
cincura.net
Posts: 593
Joined: 09 Dec 2005, 17:30
Location: a step further
Contact:

Post by cincura.net »

ether wrote:
Stefan wrote:So i would try this RegEx: .{7}_(.+)_.{5}\....
Salamander's implementation doesn't support precise quantificators, i.e. {n}.
So instead of

Code: Select all

.{7}
you can simply write

Code: Select all

.......
. ;)
Jiri {x2} Cincura
Post Reply