首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查找重复文件的软件*名称*

查找重复文件的软件*名称*
EN

Software Recommendation用户
提问于 2018-02-10 16:08:46
回答 1查看 45关注 0票数 1

我很难找到一些macOS软件或命令行技术,这些技术将查找具有重复文件名的文件,而不考虑文件内容。

我尝试过的大多数软件都比较过几种东西,包括文件大小、校验和、修改日期等。为了我的目的,除了文件名之外,我不想比较任何东西。

例如,下面可以表示三个子文件夹的扫描结果,这些子文件夹包含几个具有相同文件名的文件。这里假设这些文件的内容及其元数据(创建日期等)完全不同。

代码语言:javascript
复制
2016 Travel/
    Document1.doc
    IMG_0001.jpg
    Untitled.txt
Work Documents/
    IMG_0001.jpg
    John Smith.vcf
    Untitled.txt
My Downloads/
    Document1.doc
    John Smith.vcf

你能推荐一些能做这种事情的软件吗?

EN

回答 1

Software Recommendation用户

发布于 2018-02-11 09:22:40

您可以很简单地使用python或python控制台(python是在macOS IIRC上预装的,也可以用于python.org中的任何平台)。

以下是交互式会话中的内容,但也可以轻松地放入脚本中。

代码语言:javascript
复制
import os
import collections
import sys

# Dictionary for lists of paths where each name is found
npdict = collections.defaultdict(list)    

# We need to collect all of the names with where they are found
startfrom = '.'  # This could be taken from input arguments in a script
for root, dirs, files in os.walk(startfrom):  # Walk the file structure 
    if '.git' in dirs:  # We don't 
        dirs.remove('.git')
    for fn in files:
        npdict[fn].append(root)

# Now to find the duplicates by making a dictionary of filenames 
# that have more than one path
dups = {fn:pths for fn, pths in npdict.items() if len(pths) > 1}

# For the moment just print them out
for fn, pths in dups.items():
    print('Filename:', fn, 'found in:')
    for pth in pths:
         print('\t', pth)
票数 2
EN
页面原文内容由Software Recommendation提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://softwarerecs.stackexchange.com/questions/48598

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档