question 188 Files & Directories · hard
Find duplicate uploads
People upload the same file again and again under different names (orders (2).csv, copy of orders.csv). Find the groups of files in a folder whose contents are exactly the same, byte for byte, so the copies can be cleaned up.
Function
duplicate_groups(folder)Comparethe files' bytes:
path.read_bytes(); two files with the same size but different bytes are not duplicatesReturnsa list of groups; each group is a sorted list of file names (2 or more) with identical contents; groups are sorted by their first name;
[] when there are no duplicatesIgnoresub-folders and the files inside them
Examples
callduplicate_groups('uploads')returns[['a_orders.csv', 'copy of orders.csv', 'orders (2).csv'], ['notes-final.txt', 'notes.txt']]
callduplicate_groups('unique')returns[]
callduplicate_groups('blanks')returns[['one.txt', 'two.txt']]