Rename script needed

Discuss and share scripts and script files...

Rename script needed

Postby ivan » 08 Apr 2008 13:04

Hello,

I had a great experience with a script that jacky gave me. Scripting is certainly a powerful thing so I'm wondering if it can do a little something I'm after.

Basically, I have a list of files. They have same names at the beginning with incrementing and same names at the end (incl extensions). However, stuff in the middle is different and i'd like to trim the list down by getting rid of that stuff in the middle.

Example:

abc.01.def.ghi.extension
abc.02.jkl.ghi.extension
abc.03.mno.ghi.extension

and so on...

What I'm after is a script that would go through the list of files and remove the def/jkl/mno/... parts while retaining the rest. I know something like this could be tricky so thank you very much in advance. If something isn't clear then please ask here or PM me, thanks again :)
ivan
 
Posts: 577
Joined: 02 Apr 2008 11:52

Postby jacky » 08 Apr 2008 13:27

hmm.. not sure if that's possible just based on parts the are the same or not, but if it's always the same structure, for example the names are always somtehing + dot + numbers + dot + something you want out + dot + something + dot + extension, then I guess it could be done.

Although, no script required here, just a RegExp Rename job. Something like this should do it:
Code: Select all
^(.+\.[0-9]+\.).*\.([^.]+?\.[^.]+?)$>$1$2
Proud XYplorer Fanatic
jacky
XYwiki Master
 
Posts: 3106
Joined: 23 Aug 2005 21:25
Location: France

Postby ivan » 08 Apr 2008 13:34

Using your analogy what I'm after is this:

samething1.mixture of numbers and letters (numbers incrementing).always different.samething1.extension

needs to become this:

samething2.mixture of numbers and letters (numbers incrementing.samething2.extension

I hope it's clearer :P And how is such RegExp Rename job applied? Thanks
ivan
 
Posts: 577
Joined: 02 Apr 2008 11:52

Postby j_c_hallgren » 08 Apr 2008 14:30

ivan wrote:I hope it's clearer :P And how is such RegExp Rename job applied? Thanks
It's executed by selecting the files, and then using File | Rename Special | RegExp Rename.

jacky's concern was about the consistency of the format of the file name before and after...basically, is there some fixed length of the parts between the "." or does it vary, and are there varying numbers of "." in the names, as those separators and/or lengths can be used to isolate the parts to be modified.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
j_c_hallgren
XY Blog Master
 
Posts: 5709
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL

Postby ivan » 08 Apr 2008 14:42

Here is some more info:

1. The format the files are in is as follows part1.part2.part3.part4.extension

where

part 1 = various words (sometimes just one, no numbers) separated by varying number of dots. No spaces between dots and/or words.

part 2 = is always 6 symbols long with mixture of letters and numbers. the numbers at the end increment by one going down the list

part 3 = always varies in terms of words, numbers, symbols and dots separating them. still no spaces between them.

part 4 = virtually always a mixture of letters, symbols and dots. numbers are rare so if they're present i can rename manually. but for each set of files that need to be renamed those letters, symbols and dots are always in the same sequence.

Part 3 is the one that needs to be removed ;)

Of course, the cases of letters need to be preserved during renaming :)

Cheers for the help!
ivan
 
Posts: 577
Joined: 02 Apr 2008 11:52

Postby Muroph » 08 Apr 2008 16:44

tried to get something to work.
but since the number of characters varies and there are dots in the middle of the parts, i can't think of a way to separate the parts in the regex.

if you are willing to count the dots after part3 then this MIGHT work.
i'm not an expert when it comes to regex, so try it with the preview.
just put replace 'dots' with the number you got.
Code: Select all
([A-Za-z.]+)([A-Za-z0-9]{6}).+((\..+){dots})>$1$2$3

say, if part4 is 'asd.fgh.jkl' in the file

part1.part2.part3.asd.fgh.jkl.extension

4 dots
Muroph
 
Posts: 561
Joined: 21 Aug 2007 15:13

Postby ivan » 08 Apr 2008 17:09

Thanks! The number of dots in part 4 most of the time = 1 (excluding those that actually bind the part, including them it'd be = 3). Two at the most (4 including bounds). There's also always just one "-" (dash/mnus) in part 4 too. I hope it helps and thanks again :)
ivan
 
Posts: 577
Joined: 02 Apr 2008 11:52

Postby Muroph » 08 Apr 2008 19:02

is there character that always appears in the first part of part4 (before the 1st dot) and never in part3 or in the rest of part4 simultaneously?
example:
if the dash in part4 is always b4 the 1st dot.

if that's the case i can problably make the regex automatic.
Muroph
 
Posts: 561
Joined: 21 Aug 2007 15:13

Postby ivan » 08 Apr 2008 19:27

The dash is always before the extension dot. In other words, there are no dots in between the dash in part 4 and the extension dot.

However, sometimes there is a dash in part 3. Will that complicate things?

Thanks for your help, you live and learn :D
ivan
 
Posts: 577
Joined: 02 Apr 2008 11:52

Postby Muroph » 09 Apr 2008 01:31

the problem here is to find where part3 ends and part4 begins.
if the dash was always in the first part of part4 i could use it to mark where the regex must stop deleting.
this is how i made it find where part3 starts, since numbers always appear in part2, but never in part1.

dashes won't be a problem.
but numbers in part1 will mess up everything.
and part2 must not have more than 6 chars.

this regex ignores part2's lenght.
Code: Select all
([A-Za-z.]+)([A-Za-z0-9]+)\..+((\..+){dots})>$1$2$3

remember to test it.
never trust a regex.
Muroph
 
Posts: 561
Joined: 21 Aug 2007 15:13

Postby j_c_hallgren » 09 Apr 2008 01:38

And in some cases, I've had to do it in multiple passes, using slightly different renames (plus a bit of manual editing) to get the final results...
The inconsistency in format is what is the problem, so if you can get it more standardized, you may have better luck!
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
j_c_hallgren
XY Blog Master
 
Posts: 5709
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL

Postby ivan » 09 Apr 2008 08:08

If it helps to narrow things down, then here's some more info:

The dash in part4 is always between the only dot in part4 and the extension dot.
ivan
 
Posts: 577
Joined: 02 Apr 2008 11:52

Postby Muroph » 09 Apr 2008 13:09

ivan wrote:The dash in part4 is always between the only dot in part4 and the extension dot.

if there's only one dot in part 4 just use that regex with '3' where 'dots' is.

the dash would help only if it were between part3 and the 1st dot in part4.
Muroph
 
Posts: 561
Joined: 21 Aug 2007 15:13

Postby Twisten » 27 Apr 2008 09:35

hmmm,
from what you're describing it seems like normalizing tv video file names, if so don't be shy just say so i might have a few tips to share and
might learn a thing or two along the way. :)
Twisten
 
Posts: 187
Joined: 27 Apr 2008 09:30

Postby ivan » 07 May 2008 14:06

you nailed it on the head there! :D though the concept could be for different things, such as chapters of books and stuff like that :) wouldn't mind hearing your tips if you care to share, thanks.
ivan
 
Posts: 577
Joined: 02 Apr 2008 11:52

Next

Return to Script Exchange



Who is online

Users browsing this forum: No registered users and 4 guests