Created
January 14, 2013 10:51
-
-
Save airekans/4529257 to your computer and use it in GitHub Desktop.
Backup and un-backup file in Python
This file contains hidden or 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
| #! /usr/bin/env python | |
| import sys | |
| import os | |
| if __name__ == '__main__': | |
| for f in sys.argv[1:]: | |
| os.system('mv -v %s %s.bak' % (f, f)) |
This file contains hidden or 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
| #! /usr/bin/env python | |
| import sys | |
| import os | |
| import re | |
| if __name__ == '__main__': | |
| if len(sys.argv) < 2: | |
| print "Please give bak files" | |
| sys.exit(1) | |
| bak_ext = re.compile(r"(?P<filename>.*)\.bak") | |
| for f in sys.argv[1:]: | |
| result = re.match(bak_ext, f) | |
| if result is None: | |
| print "Skip %s: not ends with .bak" % f | |
| else: | |
| os.system('mv -v %s %s' % (f, result.group('filename'))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment