Dealing with paths and filenames in python3

This is a quick reference for some of the common operations on filenames and paths in python3

Extract filename from path

import os
# base = 'file.ext'

Extract filename from path without extension


import os
# base_without_extension = 'file'

Extract full path to directory containing a file


import os
directory_path = os.path.dirname('/path/to/file.ext')
# directory_path = '/path/to'