Dec-28-2017, 08:28 PM
hi all,
I got this code:
Could you please help me to fix this code?
I got this code:
import os
def renamer(folder):
dirname = folder
files = os.listdir(folder)
os.chdir(folder)
for i in files:
os.rename(i, dirname + '_' + i)
renamer('abc')it works if I give an example folder to the function. But it doesnt work in a for cycle like this:for i in os.listdir('.'):
renamer(i)i have tons of folders that contain video files like this: file-1.mp4, file-2.mp4, file-3.mp4, and I'd like the files renamed a way that the new filename would contain the parent directory's name included: abc_file-1.mp4Could you please help me to fix this code?
