Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python
- import glob
- from sys import argv
- from argparse import ArgumentParser
- from os import rename
- _parser = ArgumentParser(
- "Strip28Bit",
- description= "Strips multi-byte UNICODE strings in"
- " filenames into 7-bit ASCII strings",
- allow_abbrev= True
- )
- def strip_non8bit(data: str) -> str:
- _tmpbuf = []
- for char in data:
- if ord(char) < 128: _tmpbuf.append(data)
- return ''.join(_tmpbuf)
- _parser.add_argument(
- "-r", type= bool,
- default= False,
- help= "Recursively searches through nested folders",
- dest= "isRecursive"
- )
- _parser.add_argument(
- "pattern", type=str
- )
- _args = _parser.parse_args()
- files = glob.glob(_args.pattern, recursive=_args.isRecursive)
- if len(files) == 0:
- print("No files found by the expression provided.")
- # Do the actual process of stripping unicode chars that doesn't
- # fit into the 7-bit integer (max=127) ASCII range.
- for file in files:
- rename(file, strip_non8bit(file))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement