Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Regular Expressions...
Old 08-17-2006, 08:46 PM Regular Expressions...
Brian07002's Avatar
Defies a Status

Posts: 2,140
Name: ...
Location: ...
Trades: 0
Could someone here help me out with a Regular Expression?

Here goes...

I have Filenames that are Very Long (Lots of Characters)...

What I need to do is shorten them down to 28 characters including the dot and 3 character extension (keeping in mind that spaces and () should be allowed in the filename...So, for example:

Code:
A Very Long Filename (28 chr).exe
Just used the (parenthesis at the end) to show example, but they may be located anywhere in the filename.

I am using RegexBuddy 2.21 to do my coding.

Tia,
-Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-18-2006, 01:24 AM Re: Regular Expressions...
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
This is just a pattern you could use of how to grab what you want.

Code:
([^.]{1,28})[^.]*(\..{3})
Where the first parenthesis contains the filename you'll use and the last contains the dot and extension. Then all you have to do is rename the file with first set and second set of parenthesis.

I know it could be improved but lets explain the code.

First set of parenthesis grabs everything that is not a dot from 1-28 characters, next is to move through all the rest of the characters that aren't dots and the second set of parenthesis grabs the dot and the extension.

Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 08-19-2006, 12:21 AM Re: Regular Expressions...
Brian07002's Avatar
Defies a Status

Posts: 2,140
Name: ...
Location: ...
Trades: 0
Hi,

Thank you for your reply, however, I can't seem to get it working...Could you shine some light on this bit for me? I just don't get the concept of how to make the code work. I opened up Editpad pro, and opened the search, copied the regex code you gave me into the search box, and then hit replace...Nothing worked.

Let me shed a bit of light here, I have a text file that I made like this, from an Ms-Dos box, I did: "Dir /x/b>files.txt" (without quotes) and got a text file with the contents of that directory. Now I am trying to take that text file and shorten all the filenames in that text file down to 28 characters including the period and three letter extension. I want the filenames to be shortend like this: From the left of the dot (before the extension) I want to cut the filename. Example: If the filename was:

Code:
A very interesting filename that needs to be shortend.exe
It would now be:

Code:
A very interesting file.exe
The above codes show the long filename and the one below that shows it cut down to only 28 characters INCLUDING the Extension.

And remember the filename will include parenthesis ( ), brackets [ ] spaces, and or numbers so the reg expression must be able to interept that as well.

Can you help further?

Tia for your time, and efforts!
-Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 08-19-2006 at 12:47 AM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 08-19-2006, 01:04 AM Re: Regular Expressions...
Brian07002's Avatar
Defies a Status

Posts: 2,140
Name: ...
Location: ...
Trades: 0
Hey,

If regular expressions seems to difficult to accomplish this, I could even use a basic file renaming tool, but I can't seem to find one that will batch rename the actual files to only 28 characters including the extension. Might you know of any such freeware tool?

Tia,
-Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 08-19-2006, 06:26 AM Re: Regular Expressions...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
File Renamer Download batch file renamer (fully functional 20 day trial)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Regular Expressions...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16624 seconds with 12 queries