Python sqlite3:删除包含相同文件的带有延迟路径的行

问题描述 投票:0回答:1

我在sqlite3中有表,其中包含列,我将其称为文件名,如下所示,

filename
---------------
C:\path1\111.pdf

C:\path2\111.pdf

C:\path1\123.pdf

C:\path2\241.pdf

我想要使用python的正确方法来删除重复的文件名,

因此在此示例中,我想删除111.pdf,因为我们有两个,

我只想保留一个。

python python-3.x sqlite
1个回答
0
投票
def duplicates(path):
        unique = []
        for file in os.listdir(path):
            if os.path.isfile(file):
                filehash = md5.md5(file(file).read()).hexdigest()
            if filehash not in unique: 
                unique.append(filehash)
            else: 
                os.remove(file)
© www.soinside.com 2019 - 2024. All rights reserved.