1
0
mirror of https://github.com/ciromattia/kcc synced 2026-01-30 17:07:41 +00:00

Add "1" if sanitized filename already exists (fixes #50)

This commit is contained in:
Ciro Mattia Gonano
2013-05-28 12:17:08 +02:00
parent 33fb13a66e
commit 7c3a762107

View File

@@ -579,14 +579,16 @@ def slugify(value):
def sanitizeTree(filetree):
for root, dirs, files in os.walk(filetree):
for root, dirs, files in os.walk(filetree, False):
for name in files:
if name.startswith('.') or name.lower() == 'thumbs.db':
os.remove(os.path.join(root, name))
else:
splitname = os.path.splitext(name)
os.rename(os.path.join(root, name),
os.path.join(root, slugify(splitname[0]) + splitname[1]))
slugified = slugify(splitname[0])
while os.path.exists(os.path.join(root, slugified + splitname[1])):
slugified += "1"
os.rename(os.path.join(root, name), os.path.join(root, slugified + splitname[1]))
for name in dirs:
if name.startswith('.'):
os.remove(os.path.join(root, name))