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
Asked
Active
Viewed 3,388 times
1 Answers
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/
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