Ver Fonte

refactor; make --exclude work as expected

dennisro há 5 anos atrás
pai
commit
1e9d2f96e7
1 ficheiros alterados com 15 adições e 16 exclusões
  1. 15 16
      2.py

+ 15 - 16
2.py

@@ -43,24 +43,23 @@ else:
 def findDup(parentFolder):
     # Dups in format {hash:[names]}
     dups = {}
-    print()
     for dirName, subdirs, fileList in os.walk(parentFolder):
-        if args.exclude and dirName in args.exclude:
-            continue
-        else:
-            print('  Scanning %s...' % dirName)
-            for filename in fileList:
-                # Get the path to the file
-                path = os.path.join(dirName, filename)
+        # remove excluded dirs from list
+        for exclude in args.exclude:
+            subdirs[:] = [dn for dn in subdirs if dirName+'/'+dn != exclude]
+        print('  Scanning %s...' % dirName)
+        for filename in fileList:
+            # Get the path to the file
+            path = os.path.join(dirName, filename)
+            # Calculate hash
+            if os.path.exists(path):
                 # Calculate hash
-                if os.path.exists(path):
-                    # Calculate hash
-                    file_hash = hashfile(path)
-                    # Add or append the file path
-                    if file_hash in dups:
-                        dups[file_hash].append(path)
-                    else:
-                        dups[file_hash] = [path]
+                file_hash = hashfile(path)
+                # Add or append the file path
+                if file_hash in dups:
+                    dups[file_hash].append(path)
+                else:
+                    dups[file_hash] = [path]
     return dups