How to split path names

Splitting Pathnames


import os # w  w  w .j  a  va  2 s  .co  m
path = "c:/"
print os.path.split(path)
print os.path.splitext(os.path.basename(path))


print os.path.split("c:\\a\\b\\c.mp3")                  
(filepath, filename) = os.path.split("c:\\a\\b\\c.mp3")
print filepath                                                          
print filename                                                            
(shortname, extension) = os.path.splitext(filename)                   
print shortname 
print extension 




















Home »
  Python »
    Advanced Features »




Exception Handling
File
Module