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 

One thought on “Python extract filename and extension from filepath

  1. I like the helpful information you provide on your articles. I will bookmark your blog and check again here frequently. I am fairly certain I will be told a lot of new stuff right right here! Best of luck for the following!|

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.