私はchecksumdir(https://github.com/cakepietoast/checksumdir)ライブラリを使って、ディレクトリの内容に基づいてMD5ハッシュを計算するPythonスクリプトを作成しました。機械的なハードドライブにある350 MBのディレクトリのこのハッシュを計算するのに数秒かかります。ディレクトリの内容からaを計算するにはどのくらいの時間が必要ですか?
しかし、30ギガバイトのディレクトリのハッシュ計算には年月がかかります。私はそれを終了していない、私は12 +時間がとにかく長すぎることがわかった。私は何が起こるかわからない、私が考えることができる1つのことは350メガバイトのディレクトリが私のRAMメモリに収まるということです、30ギガバイトはありません。チェックサムディレクトリのブロックサイズは64 * 1024(65536)と思われます。これはGoogleとの比較では妥当な数値です。
また、350mbdirには466個のファイルが含まれていましたが、30gbのディレクトリには22696個のファイルが含まれていました。私が推測すれば、私はまだ必要以上の時間を説明することはできません。
FWIW:スクリプトを使用して、重複した内容のディレクトリを探したいとします。私はそれを行うアプリケーションを見つけられませんでした。ですから、私はハッシュを計算し、最終結果をHTMLファイルに表示したいと思います。
関連するコード:
#!/usr/bin/env python3
import os
import re
from checksumdir import dirhash # https://pypi.python.org/pypi/checksumdir/1.0.5
import json
import datetime
now = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M")
results = {}
sorted_results = {}
single_entries = []
compare_files = False
compare_directories = True
space_to_save = 0
html_overview = []
html_overview.extend(['<!DOCTYPE html>','<html>','<head>','<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">','</head>','<body>',' <table style="width:90%" class="table table-hover table-striped">', ' <tr>',' <td colspan=4></td>',' </tr>'])
# Configuration
root = "/home/jeffrey/Documenten" # Root directory to start search
create_hash = True
calculate_file_folder_size = True
compare_file_folder_names = False
sort_by = "hash" # Options: hash, size, name
json_result_file = 'result_' + now + '.json'
html_result_file = "DuplicatesHtml-" + now + ".html"
only_show_duplicate_dirs = True
remove_containing_directories = True
verbose_execution = True
# Calculate size of directory recursively - http://stackoverflow.com/questions/1392413/calculating-a-directory-size-using-python
def get_size(start_path = '.'):
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)/1048576 # size from bytes to megabytes
return total_size
# Calculate comparison properties, sort and save based on os.walk for recursive search
for dirName, subdirList, fileList in os.walk(root):
for dir in subdirList:
dir_name = dir
dir = os.path.join(dirName, dir)
if dir[0] != ".":
if verbose_execution = True:
print(dir)
if calculate_file_folder_size == True:
size = get_size(dir)
if verbose_execution = True:
print(size)
if create_hash == True:
hash = dirhash(dir, 'md5')
if verbose_execution = True:
print(hash)
results[dir] = [dir_name, size, hash]