Skip to content

Instantly share code, notes, and snippets.

@nsporillo
Last active January 23, 2016 00:47
Show Gist options
  • Save nsporillo/11027146 to your computer and use it in GitHub Desktop.
Save nsporillo/11027146 to your computer and use it in GitHub Desktop.
Simple Python script which removes all comments from a source generated from JD-GUI
import os
import fnmatch
import re
pattern = re.compile(r"(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)")
for root, dirs, files in os.walk("."):
for name in fnmatch.filter(files, "*.java"):
file = os.path.join(root, name)
with open(file, mode='r+') as f:
rep = pattern.sub(r"", f.read())
f.seek(0)
f.write(rep)
f.truncate()
print ("Successfully removed comments from:", file)
print ("Finished source file comment removal")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment