mirror of
https://github.com/ciromattia/kcc
synced 2026-10-18 07:22:33 +00:00
Add "1" if sanitized filename already exists (fixes #50)
This commit is contained in:
+5
-3
@@ -579,14 +579,16 @@ def slugify(value):
|
|||||||
|
|
||||||
|
|
||||||
def sanitizeTree(filetree):
|
def sanitizeTree(filetree):
|
||||||
for root, dirs, files in os.walk(filetree):
|
for root, dirs, files in os.walk(filetree, False):
|
||||||
for name in files:
|
for name in files:
|
||||||
if name.startswith('.') or name.lower() == 'thumbs.db':
|
if name.startswith('.') or name.lower() == 'thumbs.db':
|
||||||
os.remove(os.path.join(root, name))
|
os.remove(os.path.join(root, name))
|
||||||
else:
|
else:
|
||||||
splitname = os.path.splitext(name)
|
splitname = os.path.splitext(name)
|
||||||
os.rename(os.path.join(root, name),
|
slugified = slugify(splitname[0])
|
||||||
os.path.join(root, slugify(splitname[0]) + splitname[1]))
|
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:
|
for name in dirs:
|
||||||
if name.startswith('.'):
|
if name.startswith('.'):
|
||||||
os.remove(os.path.join(root, name))
|
os.remove(os.path.join(root, name))
|
||||||
|
|||||||
Reference in New Issue
Block a user