Stumbling Toward 'Awesomeness'

A Technical Art Blog

Saturday, October 25, 2008

Weekend Python Snippet- (Pt. 1)

I am anal-retentive about data retention. There, I said it. There are many times when I find myself in the situation of having two storage devices, that may or may not have duplicate files. I then want to erase one, but do I have all those files backed up?

I use two existing programs to aid me in my anal-retentivity: TerraCopy and WinMerge. Terracopy replaces the windows default copy with something much better (can hash check files when they are copied, etc). With WinMerge, I can right click a folder and say ‘Compare To…’ then right click another and say ‘Compare’. This tells me any differences between the two file/folder trees.

However, here’s an example I have not yet found a good solution for:

I want to erase a camera card I have, I am pretty certain I copied the images off –but how can I be sure! I took those images and sorted them into folders by location or date taken.

So I wrote a small and I am sure inefficient python script to help:

import os
filenames = []
i = 1
path1 = 'D://photos//south america//'
path2 = 'N://DCIM//100ND300//'
if os.path.isdir(path1):
	if os.path.isdir(path2):
		print "creating index.."
for (path, dirs, files) in os.walk(path1):
	for file in files:
for (path, dirs, files) in os.walk(path2):
	for file in files:
		if os.path.basename(file) not in filenames:
			print os.path.abspath(os.path.join(path,file)) + ' not found in ' + path1 + ' file cloud'

This will print something like this:

N:/DCIM/100ND300/image.NEF not found in D:/photos/south america/ file cloud

I don’t use python that often at all, please lemme know if there’s a better way to be doing this.

posted by Chris at 6:01 PM  

1 Comment »

  1. That’s a decent level of knowledge with Python. I’m just studying it now- and hoping to transition from other languages.
    Your script is well done!

    Comment by Jordan — 2009/04/23 @ 3:54 AM

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress