for folder in directory python code example
Example 1: get list of folders in directory python
import os
my_list = os.listdir('My_directory')
Example 2: list of files in python
import os
def fn(): # 1.Get file names from directory
file_list=os.listdir(r"C:\Users")
print (file_list)
#2.To rename files
fn()
Example 3: how to get all folders on path in python
os.walk(directory)
[x[0] for x in os.walk(directory)]
Example 4: list files python
import glob
files=glob.glob(given_path)