Skip to content

Commit 1b7b44f

Browse files
committed
fix: using shutil.rmtree to remove the entire folder
1 parent 10107b6 commit 1b7b44f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

scripts/clone_access_modules.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import sys
3+
import shutil
34
from git import Repo
45
import os
56

@@ -20,13 +21,13 @@
2021
if os.path.isdir(folder_path+"/"+file) and file != ".git" and file != ".github" and file != "secrets":
2122
os.rename(folder_path+"/"+file, "./Access/access_modules/"+file)
2223

23-
# remove the cloned repo folder entirely with all its contents which includes folders and files
24-
for root, dirs, files in os.walk(folder_path, topdown=False):
25-
for file in files:
26-
os.remove(os.path.join(root, file))
27-
for dir in dirs:
28-
os.rmdir(os.path.join(root, dir))
29-
os.rmdir(folder_path)
24+
# remove the cloned repo folder entirely with all its contents which includes folders and files using shutil.rmtree()
25+
# shutil.rmtree() sometimes throws an error on windows, so we use try and except to ignore the error
26+
try:
27+
shutil.rmtree(folder_path)
28+
except Exception as e:
29+
print(e)
30+
print("failed to remove "+folder_path+" folder.")
3031

3132
print("Cloning successful!")
3233

0 commit comments

Comments
 (0)