'IsADirectoryError in python3 while trying to create a directory if not exist if exist remove and create a main and a sub-directory

import os
import shutil
dest = 'tmp/abc'
try:
  if not os.path.exists(dest):
    os.makedirs(dest)
  else:
    shutil.rmtree(dest)
    os.makedirs(dest)
except OSError as err:
  print(err)

IsADirectoryError: [Errno 21] Is a directory:



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source