Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > String code required please

Reply
Thread Tools

String code required please

 
 
dapgy@yahoo.com
Guest
Posts: n/a
 
      10-14-2005
Does someone have the Python code to pull just the filename and
extension from the end of an absolute path please.

Thanks in advance ...

 
Reply With Quote
 
 
 
 
SPE - Stani's Python Editor
Guest
Posts: n/a
 
      10-14-2005
import os
fileName = os.path.basename(absolute)
base, ext = os.path.splitext(fileName)

Stani

http://pythonide.stani.be

 
Reply With Quote
 
 
 
 
da_hmea98@hotmail.com
Guest
Posts: n/a
 
      10-14-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Does someone have the Python code to pull just the filename and
> extension from the end of an absolute path please.
>
> Thanks in advance ...


# Here you go...
import os.path

# Example path
p1 = "C:\\WINDOWS\\system32\\DirectX\\Dinput\\mse.i ni"

# This will return: 'mse.ini'
os.path.basename(p1)

"""
You can read more about manipulating file paths by reading the Python
documentation under "6.2 os.path -- Common pathname manipulations".

DA
"""

 
Reply With Quote
 
 
 
Reply

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please Help Its urgent C++ Code required ch_mshahid General Computer Support 1 07-31-2008 01:35 PM
Create a VD with required properties on a required Web Server (Windows Advanced Server 2000 has 3 Web Servers) Just D. ASP .Net 0 03-10-2006 06:02 AM
Please please please help this guy with his open source java app casioculture@gmail.com Java 4 05-05-2005 08:24 AM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments