Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get list of folders in directory python

import os 
my_list = os.listdir('My_directory')
Comment

list directory in python

from os import listdir

## Prints the current directory as a list (including file types)
print(os.listdir())
Comment

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']
Comment

python3 list directories

import os

arr = os.listdir("c:/temp/")

print("
".join(arr))
Comment

PREVIOUS NEXT
Code Example
Python :: sum in python 
Python :: what is readline() in python 
Python :: Tree: Inorder Traversal 
Python :: __str__python 
Python :: py scrapy 
Python :: float and int difference 
Python :: sum function python 
Python :: python tuple methods 
Python :: python list tutorial 
Python :: text to speech program in python 
Python :: hide console in python build 
Python :: pythpn data tyoe 
Python :: Matching a pattern in python 
Python :: reading a dataset in python 
Python :: how to find last element in array python 
Python :: socket.accept python 
Python :: how to print name in python 
Python :: docstring 
Python :: iterator in python 
Python :: python developer job description 
Python :: thresholding with OpenCV 
Python :: how to add one to the index of a list 
Python :: infinite for loop in python 
Python :: show chrome devtools in selenium 
Python :: print function python 
Python :: sort array numpy 
Python :: first non repeating charcter in string ython 
Python :: how to add to end of linked list python 
Python :: arduino loop array 
Python :: I**2 python 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =