Page 1 of 1
Batch rename with parts of path
Posted: 05 Jul 2008, 19:09
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
Posted: 08 Jul 2008, 04:10
by SelfMan
You have to use regular expressions.
Something like: xxx([a-z]+)xxx
The content of () will be placed in $(0).
Posted: 08 Jul 2008, 12:42
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')?
Posted: 08 Jul 2008, 18:40
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.
Posted: 09 Jul 2008, 12:22
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...
Posted: 09 Jul 2008, 18:11
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.
Posted: 09 Jul 2008, 23:46
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.
Posted: 11 Jul 2008, 09:18
by Jan Rysavy
Does it work for you? Please let us know...
Posted: 18 Jul 2008, 12:57
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}\....
Posted: 18 Jul 2008, 14:07
by Ether
Stefan wrote:So i would try this RegEx: .{7}_(.+)_.{5}\....
Salamander's implementation doesn't support precise quantificators, i.e. {n}.
Posted: 18 Jul 2008, 20:15
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
you can simply write
.
