file renaming from xxyyyyyyyname to xxyyyyyyy - name

hi, i have several images that are named as a 2letterfollowed by 7 numbers then a descriptive name, i would like to rename them so the id and descriptive name are separated by a " - " example

from an1234567assetimage to an1234567 - assetimage.

if possible id like to integrate this with a current script that iv made so ideally would like to use php if possible if not maybe c#. any advice?
nwalker78Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
In php
$Filename =~ m/^([a-z]+)(\d+)(.*)$/I;
$1 will have the two first letters
$2 will have the numeric portion
$3 will have all that is left.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
arnoldCommented:
preg_match('^([a-z]+)(\d+)(.*)$',$filename,$match);
$match is the array reference to the three elements.
0
arnoldCommented:
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

nwalker78Author Commented:
Thankyou
0
Ray PaseurCommented:
Putting the dash into a file name can cause some "interesting" effects if you use the name (even untentionally) in JavaScript.  Putting blanks around the dash can cause some other "interesting" effects that may require special syntax for all references to the files, such as encapsulating or putting quotes around the names.

A common workaround that allows visual and programmatic separation without these side-effects would be to put a single underscore into the file name, like this:

from an1234567assetimage to an1234567_assetimage.

The regular expression to isolate the parts will remain the same - it's just a minor difference in reassembling the parts.
0
GauthierCommented:
Don't do that in PHP, Since you are speaking of C# I assume your PHP run on Windows.
PHP doesn't support UTF16 NTFS name properly, and will only work within the 8 bit code page.
It will work on Linux when using UTF-8 file name,
But file management and renaming on windows will be a disaster.
0
GauthierCommented:
I would recommend you do that in Powershell something along those line :
Get-ChildItem "C:\folder" | Where-Object {$_.Name -match "^([a-z]+)(\d{7})(.*)$"} | Rename-Item -NewName { $_.Name -replace "^([a-z]+\d{7})(.*)$" , "$1 - $2" }

I didn't test it...
0
arnoldCommented:
Presumably this data is also in a DB, and needs to be updated simultaneously?
0
nwalker78Author Commented:
Hi yes adatabase is involved and in the main the updating of it has been taken careof.  Its just that when i changed the naming convention about 3000 images didnt get renamed properly and goin through them one by one got abit tedious lol.

Im not familiar with powershell is that built into windows7?  

Thanks for the help
0
arnoldCommented:
Yes.
0
nwalker78Author Commented:
appologies for the delay been in hospital. and forgot question was still open.
0
arnoldCommented:
NO prob on delay.  hope all is well.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.