Answers for "os.listdir only folder"

4

os.listdir in python

#import libs
import os

#set path of file or website on which listdir is to be applied
path='/users/desktop/dummy'

#Print all data in path

for file in os.listdir(path):
  print(file)
Posted by: Guest on June-06-2021
2

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']
Posted by: Guest on August-21-2020

Browse Popular Code Answers by Language