Zdobądź katalog pliku Python
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
Agreeable Ape
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
import os
files_and_directories = os.listdir("path/to/directory")
import os
print(os.listdir('/path/to/folder/to/list'))
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
import os
def fn(): # 1.Get file names from directory
file_list=os.listdir(r"C:\Users")
print (file_list)
#2.To rename files
fn()
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]