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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With