How to list all files and directories in root directory in Python

1 Answer

0 votes
import os

path = "/"

lst = os.listdir(path)

print(lst)




'''
run:

['home', 'tmp', 'bin', 'srv', 'dev', 'run', 'mnt', 'etc', 'root', 'sys', 'lib', 'proc', 'usr', 'opt', 'sbin', 'media', 'var', 'app']

'''

 



answered Jul 23, 2022 by avibootz
...