Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mouse0w0/5a8f6ae9a2cbf660fd13fbdea029e707 to your computer and use it in GitHub Desktop.
Save mouse0w0/5a8f6ae9a2cbf660fd13fbdea029e707 to your computer and use it in GitHub Desktop.
Delete unused vscode extension directories
import os
import os.path as path
import json
import shutil
print("WARNING: This script will delete unused extension directories. Press enter to continue.")
input()
extensionsDir = path.join(path.expanduser("~"), ".vscode", "extensions")
if not path.exists(extensionsDir):
print("VSCode extensions directory not exists")
exit(0)
extensionsFile = path.join(extensionsDir, "extensions.json")
with open(extensionsFile, "r") as file:
extensions = json.load(file)
ignoreExtensionRelativePaths = set()
for extension in extensions:
ignoreExtensionRelativePaths.add(extension["relativeLocation"])
for relativePath in os.listdir(extensionsDir):
absolutePath = path.join(extensionsDir, relativePath)
if path.isdir(absolutePath) and not ignoreExtensionRelativePaths.__contains__(relativePath):
print("Delete unused extension directory: " + absolutePath)
shutil.rmtree(absolutePath)
print("Done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment