Skip to content

100 Words…

New Year’s resolutions are usually a bad idea.

That said, I’ve decided to make one, and see how it goes. I’m keeping it relatively simple: write at least 100 words or a useful snippet of code every day. Yesterday’s contribution to the resolution is a little snippet of code I wrote to help me consolidate two unruly iTunes folders. On a PC, I would simply run Beyond Compare to manage them, but there doesn’t seem to be a decent Mac application to do the same thing (that doesn’t choke on a 30 Gb folder compare). This is a stupid simple little script, but it did the trick for me.


import sys, getopt, os.path, shutil

if __name__ == "__main__":
opts, args = getopt.getopt(sys.argv[1:], None)
# 3 arguments: source directory, target directory, file to write
if len(args) != 3:
print "Error"
out = open(args[2], 'w')
count = 0
for root, dirs, files in os.walk(args[0]):
for file in files:
targetroot = root.replace(args[0], args[1])
if not os.path.exists(targetroot + "/" + file):
# Switch between these two conditions for a 'dry run' and actually copying files
# if file != ".DS_Store":
# out.write(root + '/' + file + '\r\n')
# count += 1

if file != ".DS_Store":
if not os.path.exists(targetroot):
out.write(root + '/' + file + '\r\n')
count += 1
shutil.copy2(root + '/' + file, targetroot + '/' + file)
print "Total files: "
print count

I may decide to count this post for yesterday (the code) and today (the description) depending on if I get a chance to write some more.

Edit: Apparently, I broke the code tag. D’oh.