Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # LICENCE: GPLv3
- # temp files '.*~' from given directories or starting at home directory
- # usage: rm_temp.py <arg1> <arg2> ... <argn>
- # ouputs: log of which directory it is working in
- import os
- import sys
- import logging
- logger = logging.getLogger(__file__.split(".")[0])
- logger.setLevel(logging.INFO)
- channel = logging.StreamHandler()
- channel.setLevel(logging.DEBUG)
- formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
- channel.setFormatter(formatter)
- logger.addHandler(channel)
- if len(sys.argv) > 1:
- for each in sys.argv[1:]:
- logger.info("removing temp files from directory %s" % each)
- os.system(r"find %s -regex .*~$ -exec rm '{}' \;" % each)
- else:
- logger.info("removing temp files starting at home directory")
- os.system(r"find ~ -regex .*~$ -exec rm '{}' \;")
Add Comment
Please, Sign In to add comment