how to remove suffix from filename

R

royG

hi
when parsing a list of filenames like ['F:/mydir/one.jpg','F:/mydir/
two.jpg'....] etc i want to extract the
basename without the suffix...ie i want to get 'one','two' etc and not
'one.jpg'

is there a function in python to do this or do i have tosplit it ..?
thanks
RG
 
M

Mel

royG said:
when parsing a list of filenames like ['F:/mydir/one.jpg','F:/mydir/
two.jpg'....] etc i want to extract the
basename without the suffix...ie i want to get 'one','two' etc and not
'one.jpg'

is there a function in python to do this or do i have tosplit it ..?
thanks

os.path.splitext is the one, it think.
 
L

Larry Bates

royG said:
hi
when parsing a list of filenames like ['F:/mydir/one.jpg','F:/mydir/
two.jpg'....] etc i want to extract the
basename without the suffix...ie i want to get 'one','two' etc and not
'one.jpg'

is there a function in python to do this or do i have tosplit it ..?
thanks
RG

import os

fname='F:/mydir/two.jpg'
filenameonly=os.path.splitext(os.path.basename(fname))[0]

-Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top