os.walk python 3 code example

Example 1: os walk example

import os
folder_path = r'C:\Test'
for root,dirs,files in os.walk(folder_path, topdown=True):
  print(root)
  print(dirs)
  print(files)

Example 2: python os module

#the os module provides an operating system interface from Python
import os
#prints the name of the operating system
print(os.name)
#prints the absolute path for the module
print(os.getcwd())

Example 3: os.walk python

# !/usr/bin/python

import os
for root, dirs, files in os.walk(".", topdown=False):
   for name in files:
      print(os.path.join(root, name))
   for name in dirs:
      print(os.path.join(root, name))