Answers for "get filename from directory python"

33

python get filename from path

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

python get files in directory

from pathlib import Path
for txt_path in Path("/path/folder/directory").glob("*.txt"):
  print(txt_path)
Posted by: Guest on November-30-2020
2

python how to get the folder name of a file

# Basic syntax:
import os
os.path.dirname('/path/to/your/favorite/file.txt')
--> '/path/to/your/favorite/'
Posted by: Guest on October-04-2020

Code answers related to "get filename from directory python"

Python Answers by Framework

Browse Popular Code Answers by Language