Skip to content

Instantly share code, notes, and snippets.

@legendmohe
Created March 26, 2021 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save legendmohe/5ec68bd60903a64c049dc4bc7177bc51 to your computer and use it in GitHub Desktop.
Save legendmohe/5ec68bd60903a64c049dc4bc7177bc51 to your computer and use it in GitHub Desktop.
在两个目录查找同名文件
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""find_same_res.py: ..."""
__author__ = "hexinyu"
import os
import argparse
import time
class DupResFinder(object):
def find(self, args):
self._find(args.first, args.second)
def _find(self, firstDir, secondDir):
firstSet = set()
for subdir, dirs, files in os.walk(firstDir):
for file in files:
firstSet.add(os.path.basename(os.path.join(subdir, file)))
secondSet = set()
for subdir, dirs, files in os.walk(secondDir):
for file in files:
secondSet.add(os.path.basename(os.path.join(subdir, file)))
print("\n".join(firstSet & secondSet))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--first", default=".")
parser.add_argument("-s", "--second", default=".")
args = parser.parse_args()
print(DupResFinder().find(args))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment