Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #!/bin/python
  2. import glob
  3. from sys import argv
  4. from argparse import ArgumentParser
  5. from os import rename
  6.  
  7. _parser = ArgumentParser(
  8. "Strip28Bit",
  9. description= "Strips multi-byte UNICODE strings in"
  10. " filenames into 7-bit ASCII strings",
  11. allow_abbrev= True
  12. )
  13.  
  14. def strip_non8bit(data: str) -> str:
  15. _tmpbuf = []
  16. for char in data:
  17. if ord(char) < 128: _tmpbuf.append(data)
  18.  
  19. return ''.join(_tmpbuf)
  20.  
  21. _parser.add_argument(
  22. "-r", type= bool,
  23. default= False,
  24. help= "Recursively searches through nested folders",
  25. dest= "isRecursive"
  26. )
  27.  
  28. _parser.add_argument(
  29. "pattern", type=str
  30. )
  31.  
  32. _args = _parser.parse_args()
  33.  
  34.  
  35. files = glob.glob(_args.pattern, recursive=_args.isRecursive)
  36. if len(files) == 0:
  37. print("No files found by the expression provided.")
  38.  
  39. # Do the actual process of stripping unicode chars that doesn't
  40. # fit into the 7-bit integer (max=127) ASCII range.
  41. for file in files:
  42. rename(file, strip_non8bit(file))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement