5

I have an main folder(map) under this main have sub folder (zoom1,zoom2,zoom3...) how can i remove sub folder using shutil. note * : I know the main folder path sub folders are dynamically created

VisioN
  • 143,310
  • 32
  • 282
  • 281
arun kumar
  • 105
  • 2
  • 10

1 Answers1

3

If you're using linux you could do the following. Use python's glob library

Lets you have a directory structure with the following structure.

  • /map

    • /map/zoom1/

    • /map/zoom2/

    • /map/zoom3/

Using glob and shutil

import glob
import shutil

sub_folders_pathname = '/map/zoom*/'
sub_folders_list = glob.glob(sub_folder_pathname)
for sub_folder in sub_folders_list:
    shutil.rmtree(sub_folder)

sub_folders_pathname is a shell-style wildcard, glob supports shell-style wildcards.

sub_folders_list are a list of folders and then we use shutil.rmtree to remove it.

tockards
  • 189
  • 6