Skip to content

Instantly share code, notes, and snippets.

@subeeshb
Created May 28, 2014 04:38
Show Gist options
  • Save subeeshb/9afe9f2947ce9f486e40 to your computer and use it in GitHub Desktop.
Save subeeshb/9afe9f2947ce9f486e40 to your computer and use it in GitHub Desktop.
Python script to delete node_modules on windows
import os, shutil
folders = []
for path, dirs, files in os.walk("./node_modules"):
head, tail = os.path.split(path)
if tail == 'node_modules':
folders.append(path)
os.mkdir('./temp_node_modules')
for i in range(len(folders)-1, 0, -1):
source = folders[i]
shutil.move(source, './temp_node_modules')
shutil.rmtree('./temp_node_modules/node_modules', ignore_errors=True)
shutil.rmtree('./temp_node_modules', ignore_errors=True)
shutil.rmtree('./node_modules', ignore_errors=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment