Splitting Pathnames
import os
os.path.split("c:\\music\\ap\\m.mp3")
(filepath, filename) = os.path.split("c:\\music\\ap\\m.mp3")
print filepath
print filename
(shortname, extension) = os.path.splitext(filename)
print shortname
print extension
# The split function splits a full pathname and returns a tuple containing the path
# and filename.
# os.path also contains a function splitext, which splits a filename and returns a
# tuple containing the filename and the file extension.
Related examples in the same category