sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
dapgy@yahoo.com's Avatar

String code required please


Question posted by: dapgy@yahoo.com (Guest) on October 14th, 2005 05:25 AM
Does someone have the Python code to pull just the filename and
extension from the end of an absolute path please.

Thanks in advance ...

2 Answers Posted
SPE - Stani's Python Editor's Avatar
SPE - Stani's Python Editor October 14th, 2005 06:15 AM
Guest - n/a Posts
#2: Re: String code required please

import os
fileName = os.path.basename(absolute)
base, ext = os.path.splitext(fileName)

Stani

http://pythonide.stani.be

da_hmea98@hotmail.com's Avatar
da_hmea98@hotmail.com October 14th, 2005 06:15 AM
Guest - n/a Posts
#3: Re: String code required please

Join Bytes! wrote:[color=blue]
> Does someone have the Python code to pull just the filename and
> extension from the end of an absolute path please.
>
> Thanks in advance ...[/color]

# Here you go...
import os.path

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

# 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
"""

 
Not the answer you were looking for? Post your question . . .
196,801 members ready to help you find a solution.
Join Bytes.com

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 196,801 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors