python get filename in directory code example
Example 1: python get filename from path
import os
print(os.path.basename(your_path))
Example 2: python get all file names in directory
import glob
print(glob.glob("/home/adam/*.txt"))
Example 3: list files in directory python
import os
print(os.listdir('/path/to/folder/to/list'))
Example 4: get files in directory python
import os
files_and_directories = os.listdir("path/to/directory")
Example 5: list of files in python
import os
def fn():
file_list=os.listdir(r"C:\Users")
print (file_list)
fn()