xxxxxxxxxx
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
xxxxxxxxxx
import os
#full path
dir_path = os.path.dirname(os.path.realpath(__file__))
#current dir
cwd = os.getcwd()
xxxxxxxxxx
from pathlib import Path
for txt_path in Path("/path/folder/directory").glob("*.txt"):
print(txt_path)
xxxxxxxxxx
import os
print('File name : ', os.path.basename(__file__))
print('Directory Name: ', os.path.dirname(__file__))
xxxxxxxxxx
import os
your_file_path = "D:\\your\\dir\\path\\file.csv"
print(f"Dir:{os.path.dirname(your_file_path)}")
#>>> Dir:D:\\your\\dir\\path
xxxxxxxxxx
# Basic syntax:
import glob
list_of_files = glob.glob("search_pattern")
# Where:
# - the search pattern can be any glob pattern, e.g. /usr/bin/*py* to get the
# list of files in /usr/bin that contain py
xxxxxxxxxx
from os import getcwd # only import "getcwd" from os
getcwd() # Get the current working directory
xxxxxxxxxx
(_, _, filenames) = os.walk(mypath).next() #if you are confident that the walk will return at least one value