Fix a bug where the normalised file would be moved. closes #1
This commit is contained in:
		@@ -1,6 +1,8 @@
 | 
				
			|||||||
from sys import argv
 | 
					from sys import argv
 | 
				
			||||||
from os import rename
 | 
					 | 
				
			||||||
from unidecode import unidecode
 | 
					from unidecode import unidecode
 | 
				
			||||||
 | 
					from os import rename
 | 
				
			||||||
 | 
					from os.path import basename, dirname
 | 
				
			||||||
 | 
					from os.path import join as joinpath
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# whitespaces will be replaced
 | 
					# whitespaces will be replaced
 | 
				
			||||||
@@ -9,12 +11,18 @@ from unidecode import unidecode
 | 
				
			|||||||
# dashes are ok
 | 
					# dashes are ok
 | 
				
			||||||
whitelist = [' ', '.', '_', '-']
 | 
					whitelist = [' ', '.', '_', '-']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for file in argv[1:]:
 | 
					for path in argv[1:]:
 | 
				
			||||||
    rename(file,
 | 
					    dir = dirname(path)
 | 
				
			||||||
 | 
					    file = basename(path)
 | 
				
			||||||
 | 
					    rename(path,
 | 
				
			||||||
           unidecode
 | 
					           unidecode
 | 
				
			||||||
           (
 | 
					           (
 | 
				
			||||||
 | 
					               joinpath
 | 
				
			||||||
 | 
					               (
 | 
				
			||||||
 | 
					                   dir,
 | 
				
			||||||
                   ''.join(ch for ch in file
 | 
					                   ''.join(ch for ch in file
 | 
				
			||||||
                           if ch.isalnum()
 | 
					                           if ch.isalnum()
 | 
				
			||||||
                           or ch in whitelist)
 | 
					                           or ch in whitelist)
 | 
				
			||||||
               )
 | 
					               )
 | 
				
			||||||
 | 
					           )
 | 
				
			||||||
           .replace(' ', '_'))
 | 
					           .replace(' ', '_'))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user