Skip to content

Instantly share code, notes, and snippets.

@jeremy-rifkin
Created December 3, 2020 03:22
Show Gist options
  • Save jeremy-rifkin/b8c70797279b300730d4b5c10177bbb3 to your computer and use it in GitHub Desktop.
Save jeremy-rifkin/b8c70797279b300730d4b5c10177bbb3 to your computer and use it in GitHub Desktop.
7zip has trouble compressing a directory on windows if it contains two filenames which differ only in capitalization... This script will find problematic file pairs and delete conflicts.
import os
import sys
def main():
filedict = {}
for path, dirs, files in os.walk(sys.argv[1]):
for f in files:
full_path = os.path.join(path, f)
l = full_path.lower()
if l not in filedict:
filedict[l] = [full_path]
else:
print("duplicate:")
print("{}".format(full_path))
print("{}".format(filedict[l][-1]))
filedict[l].append(full_path)
while True:
ans = input("Resolve filename collisions? [y/n] ")
if ans == "y":
print("resolving collisions...")
for key, entry in filedict.items():
for f in entry[1:]:
os.remove(f)
print("done")
break
elif ans == "n":
print("exiting")
break
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment