Created
February 27, 2024 09:08
-
-
Save mouse0w0/5a8f6ae9a2cbf660fd13fbdea029e707 to your computer and use it in GitHub Desktop.
Delete unused vscode extension directories
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 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