Command Book

Files and folders

List all files in a folder

import glob

for file in glob.glob("raw_data/**.*"):
    print(file)

Delete all files in a folder

import os

dir = 'path/to/dir'
for f in os.listdir(dir):
    os.remove(os.path.join(dir, f))

Folder Exists?

os.path.isdir(folder)

Create a folder

os.makedir(my_path)
os.makedirs(my_path) # <--recursive
Last updated on Tue, Apr 27, 2021
Published on Tue, Oct 17, 2017