Last active
          November 14, 2017 09:55 
        
      - 
      
- 
        Save raghughanapuram/54b259a1610ba409060c24c271756b98 to your computer and use it in GitHub Desktop. 
    Python extract filename and extension from filepath
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #Python extract filename and extension from filepath | |
| import os | |
| inputFilepath = "path/to/file/foobar.txt" | |
| filename_w_ext = os.path.basename(inputFilepath) | |
| filename, file_extension = os.path.splitext(filename_w_ext) | |
| #filename = foobar | |
| #file_extension = .txt | |
| path, filename = os.path.split("path/to/file/foobar.txt") | |
| # path = path/to/file | |
| # filename = foobar.txt | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment