Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 19th, 2008, 04:55 PM
royG
Guest
 
Posts: n/a
Default how to remove suffix from filename


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
  #2  
Old March 19th, 2008, 05:05 PM
Mel
Guest
 
Posts: n/a
Default Re: how to remove suffix from filename

royG wrote:
Quote:
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.

  #3  
Old March 19th, 2008, 07:05 PM
Larry Bates
Guest
 
Posts: n/a
Default Re: how to remove suffix from filename

royG wrote:
Quote:
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(fna me))[0]

-Larry
 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles