Skip to content

Instantly share code, notes, and snippets.

@s-hiiragi
Created March 5, 2020 16:14
Show Gist options
  • Save s-hiiragi/c6b0c54c3bb8e330197a1f80d612047f to your computer and use it in GitHub Desktop.
Save s-hiiragi/c6b0c54c3bb8e330197a1f80d612047f to your computer and use it in GitHub Desktop.
Convert long file names to short file names in current directory
import os
from ctypes import windll, create_unicode_buffer
dll = windll.LoadLibrary('kernel32.dll')
for longname in os.listdir('.'):
shortname = create_unicode_buffer(16)
dll.GetShortPathNameW(longname, shortname, 16)
if shortname.value.lower().endswith('2.csv'):
print('from:', longname)
print('to :', shortname.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment