WARNING:
This code permanently deletes the specified asset folder and all its contents. Please double‑check the asset path before running.
-
Authentication and Initialization:
The script begins by callingee.Authenticate()
(only when needed) andee.Initialize()
. -
delete_folder_contents Function:
- Uses
ee.data.listAssets({'parent': folder})
to list all children assets. - Iterates over each child:
- If the child is a folder (its type is
"Folder"
), it calls itself recursively to delete its contents, then deletes the folder. - Otherwise, it deletes the file asset directly.
- If the child is a folder (its type is
- A short sleep (
time.sleep(0.1)
) is added to avoid rate limiting.
- Uses
-
delete_asset_folder Function:
- Calls
delete_folder_contents()
on the target folder. - Then attempts to delete the folder itself.
- Calls
-
Execution:
Theasset_folder
variable is set to our target asset folder. Runningdelete_asset_folder(asset_folder)
deletes all its contents and then the folder itself.
Run this code in our Jupyter Notebook or in Terminal by executing the py
file, and it will delete the asset folder and all of its contents in one go without manual confirmation. Use with extreme caution!