Thursday, August 7, 2008

using MD5 to compare folder python script

I have been working with linux for almost 1 year now. Still, I like Windows better. Haha

This is a problem i recently trying to solve. When I using cp -r command to copy a folder, or burn a folder onto dvd, i wonder if the copy that i created is 100% correct. To do this, I use md5sum to calculate md5 of the individual files in this folder.

Here is the python script :


#!/usr/bin/python


# perform a shell command and get it's output
from commands import getoutput
# perform a shell command and get it's status (error code)
from commands import getstatusoutput
# get exit, and command line args
from sys import exit,argv

#oldPWD=getoutput('pwd')

p1md5=getoutput('(cd "' + argv[1] + '"; find . ) | sort | md5sum -b')
#print p1md5

p2md5=getoutput('(cd "' + argv[2] + '"; find . ) | sort | md5sum -b')
#print p2md5

#getstatusoutput('cd "' + oldPWD + '"')

if p1md5 == p2md5:
print "Success"
exit (0)
else:
print "Fail"
exit (1)

9 comments:

Unknown said...

Really an amazing post..! By reading your post i gained more information.Power System Projects Center in Chennai | Power System Projects Center in Velachery

Deepika said...

Very interesting article. Thanks for sharing.

NO.1 APP DEVELOPMENT SERVICES | MASSIL TECHNOLOGIES

Unknown said...

I have read your blog its very attractive and impressive.I like it your blog...
Summer Courses in Chennai | Summer Courses in Thiruvanmiyur

mekala said...

Thanks for your marvelous posting! It is very useful and good..Java Summer Courses in Chennai | Summer Courses in Chennai

Unknown said...

Thanks for your marvelous posting! It is very useful and good..DotNet Project Center in Chennai | DotNet Project Center in Velachery

poornima said...

Excellent post. I have read your blog it's very interesting and informative. Keep sharing..PHP Project Center in Chennai | PHP Project Center in Velachery

Deepika said...

Good information.

B.com Integrated Courses | Avinash College of commerce

cara menggugurkan hamil said...

just information we only provide information for those who need it
A. cara agar cepat hamil setelah selesai haid
B. cara agar cepat hamil
C. cara alami untuk segera mendapat kehamilan
D. makanan dan minuman agar cepat hamil
E. masa subur biar cepat hamil
F. panduan agar cepat hamil

for ict 99 said...

Great Article
Project Centers in Chennai
Final Year Project Domains for CSE




JavaScript Training in Chennai
JavaScript Training in Chennai