Skip to content

Instantly share code, notes, and snippets.

@lukasgabriel
Created July 20, 2021 11:19
Show Gist options
  • Save lukasgabriel/c09b0acbfa2f6c59b79c4c177dbfd3c0 to your computer and use it in GitHub Desktop.
Save lukasgabriel/c09b0acbfa2f6c59b79c4c177dbfd3c0 to your computer and use it in GitHub Desktop.
# sortfilenames.py
# Run this command first to get the LongName.txt: dir Y:\ /s /b | sort /+143 /r > LongName.txt
from pathlib import WindowsPath
paths = []
# Make sure to (re-)save the text file as UTF-8 !
with open("LongName.txt", "r", encoding="utf-8") as infile:
for line in infile:
paths.append(WindowsPath(line))
with open("LongName_sorted.txt", "w") as outfile:
for path in paths:
for component in path.parts:
if len(component) > 143:
outfile.write(f"{component.__str__()}\n ---> {path.__str__()}\n\n")
# Prints the offending path or filename first, then its full location underneath.
@totalpackage327
Copy link

totalpackage327 commented Aug 20, 2021 via email

@totalpackage327
Copy link

Lukas,

Thank you for your help. All is good now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment