'Computer > Linux' 카테고리의 다른 글
| Apache 웹서버에서 Python cgi 가능하게 하는 방법 (0) | 2012/01/09 |
|---|---|
| 리눅스에서 윈도우 파티션을 마운트 시키는 방법 (터미널) (0) | 2009/03/31 |
| 우분투 리눅스에서 vim 설정 변경. (0) | 2009/03/28 |
보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.
| Apache 웹서버에서 Python cgi 가능하게 하는 방법 (0) | 2012/01/09 |
|---|---|
| 리눅스에서 윈도우 파티션을 마운트 시키는 방법 (터미널) (0) | 2009/03/31 |
| 우분투 리눅스에서 vim 설정 변경. (0) | 2009/03/28 |
#!/usr/bin/python
import os, sys, stat, hashlib
# Check arguments
if len(sys.argv) != 3:
print 'Usage: ./compareDirs.py [Directory] [Directory]'
sys.exit(0)
# Variables
BLOCK_SIZE = 1024000000
dir1 = sys.argv[1]
dir2 = sys.argv[2]
# Iterate over files
for rootdir, subdirs, files in os.walk(dir1):
for filename in files:
pathname1 = os.path.join(rootdir, filename)
pathname2 = os.path.join(rootdir.replace(dir1, dir2, 1), filename)
if not os.path.exists(pathname2):
print pathname2 + ' does not exist.'
continue
print 'Compare ' + pathname1 + ' and ' + pathname2
# Regular file only
if stat.S_ISREG(os.stat(pathname1).st_mode):
if stat.S_ISREG(os.stat(pathname2).st_mode):
f1 = open(pathname1, 'rb')
f2 = open(pathname2, 'rb')
# Compute MD5 by reading 8192-byte blocks
f1_md5 = hashlib.md5()
f2_md5 = hashlib.md5()
while True:
block = f1.read(BLOCK_SIZE)
if not block:
break
f1_md5.update(block)
while True:
block = f2.read(BLOCK_SIZE)
if not block:
break
f2_md5.update(block)
# print f1_md5.digest()
# print f2_md5.digest()
if f1_md5.digest() != f2_md5.digest():
print '\tDifferent.'
else:
print '\tSame.'
| [Python] compareDirs.py v0.1 (0) | 2011/12/26 |
|---|
댓글을 달아 주세요