By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

String code required please

P: n/a
Does someone have the Python code to pull just the filename and
extension from the end of an absolute path please.

Thanks in advance ...

Oct 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
import os
fileName = os.path.basename(absolute)
base, ext = os.path.splitext(fileName)

Stani

http://pythonide.stani.be

Oct 14 '05 #2

P: n/a
da***@yahoo.com 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
"""

Oct 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.