Created
February 9, 2017 03:40
-
-
Save jlongman/1cb9adb38d0dd4f92a4b1db2118e6cb9 to your computer and use it in GitHub Desktop.
Mv similarly named files to a backup directory,
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
# usage: pipe an ls command with relevant files. | |
# e.g. 'ls indexea4f*.html| python wayback-files.py' | |
# | |
# assumption: your source pages are static and you don't care about the differences from different dates. | |
# my blog didn't tend to have blog entry edits | |
import sys | |
import os | |
lastname = "" | |
backupdir = os.path.join(os.curdir, "backup") | |
if not os.path.exists(backupdir): | |
os.mkdir(backupdir) | |
with open(sys.argv[1], 'r') if len(sys.argv) > 1 else sys.stdin as f: | |
filename = "" | |
for filename in f: | |
filename = filename.strip() | |
dash = filename.find("-") | |
if dash < 0: | |
print "Skipping " + filename | |
continue | |
filenameroot = filename[:dash] | |
if filenameroot != lastname: | |
lastname = filenameroot | |
print "keeping " + filenameroot | |
continue | |
print "\tmove " + filename + " to " + os.path.join(backupdir, filename) | |
os.rename(filename, os.path.join(backupdir, filename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment