RENAME A FILE USING DATE CREATED

Hi : I have a lot of invoices stored in pdf format. Here is a sample:
608_Invoice_025516 (HUBB4501609265 139231 135279), 025906 (HUBB4501622217140060LANTERN), _.pdf
Each file can hold several invoices; the file is invoices to customer 608 for the day (date file created).
To help search I would like to rename each file  as follows:
YYYYMMDD_XXX.pdf
where YYYYMMDD is date created
XXX is customer  - first three characters of file name.
Is this something python can do happily?
I have made a few attempts and got into knots, I am afraid!
Thanks!
Richard TeasdaleFinancial ControllerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Danny RobinsonIT Support ConsultantCommented:
Not sure if I am barking up the wrong tree, but you can utility to batch rename files to the format/name you require.
Sorry if this no use to you.
Richard TeasdaleFinancial ControllerAuthor Commented:
Thanks, Danny. I was thinking of this but trying to persevere with python; just need a help sometimes! Thanks again.
Richard TeasdaleFinancial ControllerAuthor Commented:
Sorted myself, thanks!

import os
import datetime



target = raw_input('Enter full directory path: ')
os.chdir(target)
allfiles = os.listdir(target)
for filename in allfiles:
    t = os.path.getmtime(filename)
    v = datetime.datetime.fromtimestamp(t)
    x = v.strftime('%Y%m%d')
    p = filename
    py = p[0:3]
    os.rename(filename, py + x +".pdf")

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
Richard TeasdaleFinancial ControllerAuthor Commented:
its my own answer...
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
Python

From novice to tech pro — start learning today.