Python 3 OS Module Script to Remove all Directories or Folders and Subdirectories Using rmdir() Method

Python 3 OS Module Script to Remove all Directories or Folders and Subdirectories Using rmdir() Method

Python 3 OS Module Script to Remove all Directories or Folders and Subdirectories Using rmdir() Method

import os

dir_path = 'uploads/temp'

try:
    os.rmdir(dir_path)
except OSError as e:
    print("Error: %s : %s" % (dir_path, e.strerror))
import os

dir_path = 'uploads'

try:
    os.rmdir(dir_path)
except OSError as e:
    print("Error: %s : %s" % (dir_path, e.strerror))
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment