我很难找到一些macOS软件或命令行技术,这些技术将查找具有重复文件名的文件,而不考虑文件内容。
我尝试过的大多数软件都比较过几种东西,包括文件大小、校验和、修改日期等。为了我的目的,除了文件名之外,我不想比较任何东西。
例如,下面可以表示三个子文件夹的扫描结果,这些子文件夹包含几个具有相同文件名的文件。这里假设这些文件的内容及其元数据(创建日期等)完全不同。
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你能推荐一些能做这种事情的软件吗?
发布于 2018-02-11 09:22:40
您可以很简单地使用python或python控制台(python是在macOS IIRC上预装的,也可以用于python.org中的任何平台)。
以下是交互式会话中的内容,但也可以轻松地放入脚本中。
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)https://softwarerecs.stackexchange.com/questions/48598
复制相似问题