Answers for "how to get file name from path in python"

4

get path to file without filename python

import os
filepath = '/a/path/to/my/file.txt'
os.path.dirname(filepath)
# Yields '/a/path/to/my'
Posted by: Guest on March-10-2020
33

python get filename from path

import os
print(os.path.basename(your_path))
Posted by: Guest on February-28-2020
0

Extract filename from path in Python

filename = os.path.basename("path/to/file/sample.txt")
Posted by: Guest on August-31-2021
1

python find file name

filesName = list(map(os.path.basename, glob.glob("..\yourPath\*txt")))
print(filesName)
Posted by: Guest on January-31-2021

Code answers related to "how to get file name from path in python"

Python Answers by Framework

Browse Popular Code Answers by Language