Skip to content

Commit 4928091

Browse files
Merge pull request geekcomputers#117 from shubhamsinghrathi/master
fixing a bug in 'batch_rename'
2 parents 5d44e41 + ef85b64 commit 4928091

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

batch_file_rename.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ def batch_rename(work_dir, old_ext, new_ext):
2424
file_ext = os.path.splitext(filename)[1]
2525
# Start of the logic to check the file extensions, if old_ext = file_ext
2626
if old_ext == file_ext:
27-
# Set newfile to be the filename, replaced with the new extension
28-
newfile = filename.replace(old_ext, new_ext)
27+
# Returns changed name of the file with new extention
28+
name_list=list(filename)
29+
name_list[len(name_list)-len(old_ext):]=list(new_ext)
30+
newfile=''.join(name_list)
31+
2932
# Write the files
3033
os.rename(
3134
os.path.join(work_dir, filename),

0 commit comments

Comments
 (0)