wlwood
2018-05-10 11:36:31 +08:00
所以,所以,一个遍历删除 node_modules 目录脚本是不是就有必要了?
···python
#!/usr/bin/env python
# encoding:utf-8
import os
import sys
import shutil
def rm_dir(path, dirname):
if dirname == "node_modules":
print ("rm: ", os.path.join(path, dirname))
try:
shutil.rmtree(os.path.join(path, dirname))
except Exception as e:
print ("rm error: ", str(e))
def rm_node_modules(root):
for path, dirname, fs in os.walk(root):
for dirn in dirname:
rm_dir(path, dirn)
def main():
if len(sys.argv) < 2:
print ('please input node_modules path! exit !')
sys.exit(-1)
path = sys.argv[1]
print (path)
rm_node_modules(path)
if __name__ == "__main__":
main()
```
(注意的是,不要去删除 公共的 node_modules 啊,否则 npm 可能也会丢了)