Guest User

Untitled

a guest
Sep 11th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. import os
  2. import os.path
  3.  
  4. alphanum = "abcde fghij klmno pqrst uvwxy z ABCDE FGHIJ KLMNO PQRST UVWXY Z 0123456789 -_= () !$@#%.,~"
  5. d = "/path/to/your/folder"
  6. for fn in os.listdir(d):
  7.     rename_flag = False
  8.     altn = ""
  9.     for c in fn:
  10.  
  11.         if c in alphanum:
  12.             altn += c
  13.         else:
  14.             altn += "_"+str(ord(c))
  15.             rename_flag = True
  16.  
  17.     if rename_flag:
  18.         os.rename(os.path.join(d,fn), os.path.join(d,altn))
Advertisement
Add Comment
Please, Sign In to add comment