python directories - ghdrako/doc_snipets GitHub Wiki

https://builtin.com/data-science/python-list-files-in-directory

How to List Files in a Python Directory

  • Use os.listdir() to print all files.
  • Use os.walk() to access files deeper into a decision tree.
  • Use the glob module to search by regular expression.
  • Use the pathlib module to generate all path file names.
  • Use the os.scandir() function to return a generator.
import os
os.mkdir("newfolder")
os.rename("new_folder","old_folder")
os.rmdir("old_folder")
print(os.getcwd()) # current working directory
print(os.listdir()) # list content of dirrectory
print(os.enviroment["PATH"]) # PATH enviroment variable