Created
January 16, 2015 22:15
-
-
Save ytoshima/9f5867c64397d6124903 to your computer and use it in GitHub Desktop.
mvts
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
#!/usr/bin/env python | |
def renamets(path): | |
import os, stat, time | |
ts = os.stat(path)[stat.ST_MTIME] | |
src = path | |
ext = time.strftime("%Y-%m-%d_%H%M%S", time.localtime(ts)) | |
dst = src + "." + ext | |
# print src | |
# print dst | |
print "renaming %s to %s\n" % (src, dst) | |
os.rename(src, dst) | |
def showHelp(): | |
msg = """usage: mvts [-v] <file ...> | |
mvts rename file with original filename + file's timestamp | |
""" | |
print msg | |
if __name__ == "__main__": | |
import sys, getopt | |
optlist, args = getopt.getopt(sys.argv[1:], 'hv') | |
if len(args) == 0: | |
showHelp(); sys.exit(0) | |
for path in args: | |
renamets(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment