Created
May 5, 2022 13:34
-
-
Save abearxiong/027f83b5735a713d1f14ea0d7c6b5c2f to your computer and use it in GitHub Desktop.
删除node_modules的文件夹
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
# path可以根据具体情况设置 | |
path = '/Users/xion/归档/km/web' | |
delete_list = [] | |
def get_py(path): | |
""" | |
1. 列出 | |
2. 打印 | |
:param path: | |
:return: | |
""" | |
list_dir = os.listdir(path) | |
for s in list_dir: | |
root = path + '/' + s | |
if os.path.isdir(root) and '.' not in s: | |
if "node_modules" not in root: | |
get_py(root) | |
else: | |
delete_list.append(root); | |
print('root', root) | |
def delete_dir_list(paths): | |
for path in paths: | |
delete_dir(path) | |
def delete_dir(path): | |
# os.rmdir(path); | |
os.system('rimraf ' + path) | |
def delete_dir_list_2(paths): | |
for path in paths: | |
shutil.rmtree(path) | |
if __name__ == '__main__': | |
print(get_py(path)) | |
# a = delete_list[0] | |
# delete_dir(a) | |
# delete_dir_list(delete_list) | |
print("delete list", delete_list) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment