SHARE
TWEET

Untitled

a guest Jan 24th, 2020 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. import os
  3. import sys
  4.  
  5. NTFS_MAX_FILENAME = 255
  6. NTFS_BAD_CHARS = "/?<>:*\"" + "".join([chr(c) for c in range(0,32)])
  7.  
  8. if len(sys.argv) < 2:
  9.     print("Usage: ntfs_fix_names.py <path>")
  10.     sys.exit(1)
  11.  
  12. for (path,dirs,files) in os.walk(sys.argv[1]):
  13.     for entry in (dirs+files):
  14.         new_name = entry
  15.         if len(entry) > NTFS_MAX_FILENAME:
  16.             name,ext = os.path.splitext(entry)
  17.             new_name = entry[::NTFS_MAX_FILENAME-len(name)] + ext
  18.         if any(char in entry for char in NTFS_BAD_CHARS):
  19.             new_name = "".join(
  20.                 [c for c in entry if c not in NTFS_BAD_CHARS])
  21.         if not new_name is entry:
  22.             cwd = os.getcwd()
  23.             os.chdir(path)
  24.             os.rename(entry,new_name)
  25.             os.chdir(cwd)
  26.             print("[%s]: \"%s\" -> \"%s\"" % (path,entry,new_name))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top