Skip to content

Instantly share code, notes, and snippets.

@baronfel
Created May 17, 2024 17:46
Show Gist options
  • Save baronfel/d64da589811210e800425b0718ca3894 to your computer and use it in GitHub Desktop.
Save baronfel/d64da589811210e800425b0718ca3894 to your computer and use it in GitHub Desktop.
#! /bin/python3
from dataclasses import dataclass
from os import walk, stat
from os.path import join
from typing import Dict
sdk_dir="/mnt/c/Program Files/dotnet/sdk/9.0.100-preview.3.24204.13"
@dataclass
class DuplicateResult:
file: str
count: int
size: int
def __eq__(self, other: object) -> bool:
return self.file == other.file
def __ne__(self, value: object) -> bool:
return self.file != value.file
def __hash__(self) -> int:
return hash(self.file)
def potential_win(self) -> int:
return (self.count - 1) * self.size
all_files: Dict[str, DuplicateResult]=dict()
for (root, dirs, files) in walk(sdk_dir, topdown=True):
for f in files:
if f.endswith("resources.dll"):
continue
if f in all_files:
all_files[f].count += 1
else:
stats=stat(join(root, f))
all_files[f] = DuplicateResult(f, 1, stats.st_size)
def potential(f: DuplicateResult):
return f.potential_win()
valid_files = [all_files[f] for f in all_files if all_files[f].count > 1]
valid_files.sort(reverse=True, key=potential)
for file in valid_files:
print(f"{file.count}\t{file.potential_win()}\t{file.file}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment