using os module functions
>>> import os >>> os.path.split(r'c:\some_folder\some_file.csv') ('c:\\some_folder', 'some_file.csv') >>> root, file = os.path.split(r'c:\some_folder\some_file.csv') >>> os.path.join(root, 'new_file.csv') 'c:\\some_folder\\new_file.csv' >>> root, ext = os.path.splitext(r'c:\some_folder\some_file.csv') >>> root 'c:\\some_folder\\some_file' >>> '_'.join((root, 'clean.csv')) 'c:\\some_folder\\some_file_clean.csv'or using pathlib module
>>> import pathlib >>> p = pathlib.Path(r'c:\some_folder\some_file.csv') >>> p.with_name('new_file.csv') WindowsPath('c:/some_folder/new_file.csv') >>> p.parent.joinpath(''.join((p.stem, '_clean.csv'))) WindowsPath('c:/some_folder/some_file_clean.csv') >>>
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs