DekGenius.com
PYTHON
get list of folders in directory python
import os
my_list = os.listdir('My_directory')
python get all folders in directory
import os
subfolders = [ f.path for f in os.scandir(folder) if f.is_dir() ]
list files in directory python
import os
print(os.listdir('/path/to/folder/to/list'))
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)
list directory in python
from os import listdir
## Prints the current directory as a list (including file types)
print(os.listdir())
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))
python list directories only
>>> [ name for name in os.listdir(thedir) if os.path.isdir(os.path.join(thedir, name)) ]
['ctypes', 'distutils', 'encodings', 'lib-tk', 'config', 'idlelib', 'xml', 'bsddb', 'hotshot', 'logging', 'doc', 'test', 'compiler', 'curses', 'site-packages', 'email', 'sqlite3', 'lib-dynload', 'wsgiref', 'plat-linux2', 'plat-mac']
python list files in directory
from os import walk
f = []
for (dirpath, dirnames, filenames) in walk(mypath):
f.extend(filenames)
break
python3 list directories
import os
arr = os.listdir("c:/temp/")
print("
".join(arr))
© 2022 Copyright:
DekGenius.com