Skip to content

Instantly share code, notes, and snippets.

@jhamon
Last active December 16, 2015 13:09
Show Gist options
  • Save jhamon/5439825 to your computer and use it in GitHub Desktop.
Save jhamon/5439825 to your computer and use it in GitHub Desktop.
Delete helper files created by running pdflatex. I hate having all that clutter in my directories after I'm done building a document or beamer presentation. Retains pdf, sty, tex, and bib files.
#!/usr/bin/python
import os
# This script deletes the garbage files generated when compiling a
# latex document. Run it from the directory you would like cleaned
# up. Source documents (those ending with *.tex, *.bib, and *.sty)
# and outputs (e.g. postscript and pdf files) are not affected.
filelist = os.listdir(os.getcwd())
keys = [x[0:-4] for x in filelist if '.tex' in x]
trash_suffixes = '.aux .log .nav .bbl .out .toc .snm .rel .blg .vrb .synctex.gz'.split(' ')
things_to_delete = []
for key in keys:
things_to_delete.extend([key+x for x in trash_suffixes])
print 'The following files will be deleted:'
for item in things_to_delete:
if os.path.isfile(item):
print item
okay = raw_input('Is it okay to delete all of these files? (y/n) ') in 'yY'
if okay:
for filename in things_to_delete:
try:
os.remove(filename)
print filename + ' deleted.'
except:
pass
else:
print 'No files deleted.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment