麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > Python > 正文

Python中使用md5sum檢查目錄中相同文件代碼分享

2020-02-23 06:21:51
字體:
供稿:網(wǎng)友

代碼如下:
"""This module contains code from
Think Python by Allen B. Downey

http://thinkpython.com

Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html

"""

import os

def walk(dirname):
    """Finds the names of all files in dirname and its subdirectories.

    dirname: string name of directory
    """
    names = []
    for name in os.listdir(dirname):
        path = os.path.join(dirname, name)

        if os.path.isfile(path):
            names.append(path)
        else:
            names.extend(walk(path))
    return names


def compute_checksum(filename):
    """Computes the MD5 checksum of the contents of a file.

    filename: string
    """
    cmd = 'md5sum ' + filename
    return pipe(cmd)


def check_diff(name1, name2):
    """Computes the difference between the contents of two files.

    name1, name2: string filenames
    """
    cmd = 'diff %s %s' % (name1, name2)
    return pipe(cmd)


def pipe(cmd):
    """Runs a command in a subprocess.

    cmd: string Unix command

    Returns (res, stat), the output of the subprocess and the exit status.
    """
    fp = os.popen(cmd)
    res = fp.read()
    stat = fp.close()
    assert stat is None
    return res, stat


def compute_checksums(dirname, suffix):
    """Computes checksums for all files with the given suffix.

    dirname: string name of directory to search
    suffix: string suffix to match

    Returns: map from checksum to list of files with that checksum
    """
    names = walk(dirname)

    d = {}
    for name in names:
        if name.endswith(suffix):
            res, stat = compute_checksum(name)
            checksum, _ = res.split()

            if checksum in d:
                d[checksum].append(name)

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 欧美特级黄色 | 免费专区 - 91爱爱 | 蜜桃网站在线观看 | 中文字幕激情 | 毛片大全在线观看 | 亚洲精品com | 久久久久久久久久性 | v11av在线视频成人 | 精品国产一区二区亚洲人成毛片 | 久久羞羞视频 | 亚欧美一区二区 | 全黄性性激高免费视频 | 国产资源在线观看视频 | 久久久噜噜噜久久熟有声小说 | 免费国产视频在线观看 | 在线看日本 | 成人免费国产 | 操碰| 国产91精品亚洲精品日韩已满 | 99国产精品欲a | 国产婷婷一区二区三区 | 国产精品亚洲欧美一级在线 | 国产精品区一区二区三区 | 国产精品久久久久久久久久三级 | 成人不卡| 在线天堂中文字幕 | 91精品国产一区二区在线观看 | 精选久久 | www成人在线观看 | 国产在线免 | 久久久久久久爱 | 国产91精品欧美 | 福利在线免费 | japanese xxxxhd| 亚洲一区在线免费视频 | 欧美综合在线观看视频 | 午夜视频在线免费 | 羞羞视频在线免费 | 羞羞视频免费观看网站 | 国产精品久久久乱弄 | 国产91一区二区三区 |