A botched OneDrive restoration has left me with many files and folders with a " (1)" or " (2)" suffix.
I would like a script (Bash is fine as I have MinGW + Cygwin, or PowerShell) that would parse all files and folders within a given folder (e.g. "d:\OneDrive" or "/cygdrive/d/OneDrive") and for each file or folder, see if there is one or more files/folders (in the same subfolder) whose file/folder name matches the regex "\1\s*\(\d+\)\.\2" where "\1" is the original file/folder name without extension, and \2 is the original extension. Then the script should binary compare the original file/folder to each of the files/folders found by the previous regex (recursively in the latter case) and if they are identical, it should delete the copy (the one with the longer filename).
While a possible basic structure of the script is clear (two nested for loops, find for finding files matching the regex, diff for comparison etc.) I'm not familiar enough with Bash scripts to comfortably put the pieces together, and there may well be a more efficient structure in any case (which would help given there are around half a million files to go through).