Welcome Guest.   Make a donation to an author on the site April 16, 2014, 11:03:36 AM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Read the full one-year retrospective report on DonationCoder.com.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Chop off extra junk in file names  (Read 2452 times)
nkormanik
Participant
*
Posts: 263

View Profile Give some DonationCredits to this forum member
« on: June 20, 2012, 05:10:52 PM »


Another little problem has come up....

I'm generating a bunch of contour plot images in a statistics program.  The resulting plot images are supposed to be named according to the script of commands as such:

_50501_22004_22404_.png
_50501_22004_22403_.png
_50501_22004_22402_.png
_50501_22004a_22401_.png
_50501_22004_22306_.png
_50501_22004_22305_.png
_50501_22004_22304_.png
_50501_22004_22303_.png
_50501_22004_22302b_.png
_50501_22004_22301_.png

I've deliberately set up this naming approach because of the problem I'm about the describe.

For some crazy reason the program creating the plot images adds numbers to the ends of the names:

_50501_22004_22404_3000.png
_50501_22004_22403_3001.png
_50501_22004_22402_3002.png
_50501_22004a_22401_3003.png
_50501_22004_22306_3004.png
_50501_22004_22305_3005.png
_50501_22004_22304_3006.png
_50501_22004_22303_3007.png
_50501_22004_22302b_3008.png
_50501_22004_22301_3009.png

I would like the original names, or, rather, the names as they were intended to be.

One solution to the problem is to create a batch file:

ren    _50501_22004_22404_3000.png    _50501_22004_22404_.png
etc.

The total number of files is in the tens of thousands.  Over repeated times.  I believe all the underlying names are unique (no repeats).

I'm wondering if any of you can come up with a better approach than creating a basic batch file to chop off that extra junk after the third underline character, but, of course, before the file name extension.

Or, chop junk BETWEEN third underline character and period of the file extension.

Some of you might come up with a magic RegEx solution?  Please then suggest, too, a RegEx program.

Or maybe one of you will create a small program to do the trick?  Hopefully generalizable so that others can use the program for their specific needs.

Not sure.  If no better solution than the creating basic batch file approach, I'll have to continue using that.

Thanks much!

Nicholas Kormanik
nkormanik@gmail.com
.

Logged
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: June 20, 2012, 05:42:22 PM »

I am not running windows, so I can't really program something to fully solve your problem.
I can, however, give you a matching regex that should do it:
[copy or print]
^(_[^_]+_[^_]+_[^_]+_).*.png$
and the replace pattern should be:
Depending on the program you use, "$1" could also be "\1" and some of the special characters such as "()+[]" may require escaping such as "\(" instead of "(".
The example I gave should work for the first google hit for "regex renamer" which actually looks pretty neat (even though I've never tried it).
« Last Edit: June 20, 2012, 05:57:28 PM by jgpaiva; Reason: oops, regex error :-[ » Logged

skwire
Moderator
*****
Posts: 3,896



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: June 20, 2012, 06:54:40 PM »

My favourite renamer is ReNamer found here: http://www.den4b.com/?x=p...ducts&product=renamer

1) Download and run.
2) Add the files/folders you want.
3) Add a RegEx rule like this:



4) You should see the preview change to this:



If you can't tell from the screenshot what the RegEx pattern is, here you go: (_.*)_.*
Logged

skwire
Moderator
*****
Posts: 3,896



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: June 20, 2012, 07:44:46 PM »

jgpaiva, nice find, that RegexRenamer.  Nick, if you choose to go with that application, here's a screenshot to help you along:

Logged

MilesAhead
Member
**
Posts: 4,445



View Profile Give some DonationCredits to this forum member
« Reply #4 on: June 20, 2012, 08:17:52 PM »

jgpaiva, nice find, that RegexRenamer.  Nick, if you choose to go with that application, here's a screenshot to help you along:
 (see attachment in previous post)

That does look interesting. I'm going to try it out myself.
Logged

"I don’t want to belong to any club that would have me as a member."
 - Groucho Marx

Target
Honorary Member
**
Posts: 1,361



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #5 on: June 20, 2012, 09:04:12 PM »

pretty much any of the 'good' renaming apps will do this for you out of the box - everyone has their preferred option but you could try BRU
Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
IainB
Supporting Member
**
Posts: 4,278


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #6 on: June 20, 2012, 10:21:15 PM »

+1 from me for BRU (Bulk Rename Utility) for this. I had a similarly rather complicated renaming problem, and my usual problem-solver (xplorer²) couldn't help. I used BRU after reading a post about it on the DC forum.

WARNING:
Using BRU makes my brain hurt, but it's a very powerful tool. You could really screw up with it big time too.
Logged
nkormanik
Participant
*
Posts: 263

View Profile Give some DonationCredits to this forum member
« Reply #7 on: June 20, 2012, 11:56:54 PM »


To all, thanks for your help.  I made a mistake in my original post:

Quote
Chop junk between third underline character and period of the file extension.

Should read:

Chop junk between FOURTH underline character and period of the file extension.

_50501_22004_22305_3005.png

i.e., the 3005 part.

Hate to bother you, but would you please adjust your RegEx?

I've downloaded all three RegEx programs and will experiment when you provide the corrected code.

Logged
Target
Honorary Member
**
Posts: 1,361



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #8 on: June 21, 2012, 12:16:28 AM »

I've downloaded all three RegEx programs and will experiment when you provide the corrected code.

FYI, if you use a renamer like BRU (and there are many) they already have the funtionality to do that, ie no regex needed.

The plus is that you can see, in real time, what your changes are going to look like before you make them, so there's plenty of time to fine tune your parameters

Logged

"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler
MilesAhead
Member
**
Posts: 4,445



View Profile Give some DonationCredits to this forum member
« Reply #9 on: June 21, 2012, 12:45:05 AM »

I've mentioned it before, but FreeCommander has a nice renamer. It's less complex than BRU but a lot better than Explorer.  For instance in the example given on RegexRenamer site about changing auto-generated filenames from a camera to a numbered sequence starting with MyPics or whatever it was.. in FreeCommander renamer you would just type the name as in MyPics[c]  then click on starting number and if to pad with how many zeroes etc..  Or if you want to keep the name and add to it you use [n] for name and [e] for extension in the extension part.  It cannot do things like BRU and remove letters from n'th position to n'th + 10 but it can do other things in a much simpler way.
Logged

"I don’t want to belong to any club that would have me as a member."
 - Groucho Marx

AbteriX
Charter Honorary Member
***
Posts: 1,020


Member #520

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #10 on: June 21, 2012, 02:28:35 AM »

Please note that Nicholas don't want to remove the last underscore, e.g. there are only 4 signs to remove.
Logged

Greetings, Stefan.
nkormanik
Participant
*
Posts: 263

View Profile Give some DonationCredits to this forum member
« Reply #11 on: June 21, 2012, 02:35:50 AM »

Thanks AbteriX for pointing that out.  Yes, I want the last underscore to remain.

As for what's between the last underscore and the period, it's variable -- from one to six digits.  That's really the crux of the problem.  The 'junk' varies in length.  Need to cut out that junk.

Probably a magic RegEx code is called for.  Look forward to the RegEx gurus coming back with updated code (sorry I made the mistake about which underscore...).


Logged
jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #12 on: June 21, 2012, 02:49:14 AM »

Hi, for ReNamer to keep the last underscore, you can use: (_.*_).*
Logged

AbteriX
Charter Honorary Member
***
Posts: 1,020


Member #520

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #13 on: June 21, 2012, 03:08:51 AM »

Nicholas, since the RegEx differs from tool to tool,... do you have an favorite now?

An RegEx for scarabee's Siren Renamer would be:
%b(s/(.+_).+/$1/).%e


- - -


Note that you can use also f.ex. den4b's ReNamer with an Rearrange Rule like this:

FROM:
_50501_22004_22404_3000.png
or
_50501_22004_22404_300012345678.png

TO:
_50501_22004_22404_.png

USE:
ReNamer Rearrange Rule:
Split by delimiters "_"
New pattern "$1_$2_$3_$4_"
(skip extension)

See > http://www.den4b.com/wiki/ReNamer:Rules:Rearrange

Also note that ReNamer has an Analyze Dialog to test such issues without the need to have the file names in real on your disk:
http://www.den4b.com/wiki/ReNamer:Analyze
Logged

Greetings, Stefan.
nkormanik
Participant
*
Posts: 263

View Profile Give some DonationCredits to this forum member
« Reply #14 on: June 21, 2012, 03:15:06 AM »


den4b's ReNamer looks really good.  I still would like to try the others, though.

Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.04s | Server load: 0.12 ]