DekGenius.com
PYTHON
list files in directory python
import os
print(os.listdir('/path/to/folder/to/list'))
pathlib get list of files
for path in pathlib.Path(".").iterdir():
if path.is_file():
print(path)
python list all files in directory
import os
arr = os.listdir()
print(arr)
>>> ['$RECYCLE.BIN', 'work.txt', '3ebooks.txt', 'documents']
get list of files in directory python
import os
path = '/folder1/folder2/'
files = os.listdir(path)
get list file in folder python
lstJson = [f for f in os.listdir(str(self.pathJson)) if f.endswith('.json')]
return lstJson
python get list of files in directory
from os import listdir
file_list = listdir(folder_path)
python list files in directory
import os
folder_path = "./folder-path"
for path, currentDirectory, files in os.walk(folder_path):
for file in files:
if not file.startswith("."):
print(os.path.join(path, file))
list all files in folder python
import os
arr = next(os.walk('.'))[2]
print(arr)
>>> ['5bs_Turismo1.pdf', '5bs_Turismo1.pptx', 'esperienza.txt']
python list files in directory
from os import walk
f = []
for (dirpath, dirnames, filenames) in walk(mypath):
f.extend(filenames)
break
how to get a list of files in a folder in python with pathlib
import pathlib
import os
directory: pathlib.Path = some/path/_object
for file in os.listdir(directory.__str__()):
file_path: pathlib.Path = directory / file
pass
© 2022 Copyright:
DekGenius.com