Removing portion of a file name

A swapping-ground for Regular Expression syntax

Removing portion of a file name

Postby sandman596 » Wed Jul 28, 2010 6:34 pm

I know it sounds like another thread, but that was too simple for needs.

Here is what I am trying to do with BRC and reg exp.

I am taking a file xfr-l1234 Boise Race 2010.jpg and moving it to its pre-made directory. It most often is the car's number and drivers last name or another description i.e. 003 Smith or R3H2 Modified Sleds, but at times it may a combination of letters and numbers or for special fun, just letters.

I am then removing the xfr from the file name and trying to replace it with only the first portion of the directory name.

I have set up BRC so that I can add the folder name to the file name, but I am having the darnedest time figuring out how to capture just the first group of numbers (or letters and/or numbers) i.e. the 003 or the R3H2 from the file name, then dropping the name or descriptor and keeping everything after the hyphen. That first group of alpha numeric is not always the same length either.

If it was always only digits, I could handle that from what learned on the other threads. It is the problem with when I get to alpha-numerics that I cannot work out.

I have tried to figure this out for about 8hrs. I have looked at all the other threads, and the only thing I know is I have a major headache.

I believe I have the stuff after the hyphen with this \-(.*)

Can someone nudge me towards an idea of how to grab only the first grouping of lettering in the file name after adding the directory name? I am hoping there is some magical expression that will do both just the numbers and the alpha-numerics.

Some more examples of the folder names that I contend with ( I really only want the first letters and/or numbers before the first space):

107 Collins I want 107 for the file name
5XA Prelim XC A I want 5XA for the file name


and for just a kicker, I sometimes add a space before the first grouping, so that it comes at the top of the directory listing
BNAA Beg Nov A Awards I want BNAA for the file name

Thank you.
sandman596
 
Posts: 2
Joined: Wed Jul 28, 2010 5:35 pm

Re: Removing portion of a file name

Postby sandman596 » Thu Jul 29, 2010 6:07 am

I think I got my head wrapped around it now. Just had to take a break from it and let it sink in.

Here is what I have for my BRC

BRC.exe /DIR:"C:\1temp" /RECURSIVE /NOFOLDERS /PATTERN:"xfr*" /REMOVEWORDS:"xfr" /APPENDFOLDER:P::1 /REGEXP:"^(.+?)\s(.+-)(.*)":"\1-\3" /NODUP /TRIM /QUIET /EXECUTE

^(.+?)\s(.+-)(.*)
^ starts at front
(.+?)\s grabs everything up to first space
(.+-) grabs everything up to hyphen
(.*) grabs everything else left

/TRIM removed the empty space in the file name from the directory the had a leading space for dir positioning at top of windows listing.

So far I think it works on all three of my different possible file naming situations.

If anyone has a more elegant or universal way of doing it, please let me know.

Thank you
sandman596
 
Posts: 2
Joined: Wed Jul 28, 2010 5:35 pm


Return to Regular Expressions