python将文件名变为拼音

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from pypinyin import pinyin, lazy_pinyin, Style

def scan_files(directory,prefix=None,postfix=None):
    files_list=[]
    
    for root, sub_dirs, files in os.walk(directory):
        for special_file in files:
            if postfix:
                if special_file.endswith(postfix):
                    files_list.append(os.path.join(root,special_file))
            elif prefix:
                if special_file.startswith(prefix):
                    files_list.append(os.path.join(root,special_file))
            else:
                files_list.append(os.path.join(root,special_file))
                          
    return files_list

path = "/mnt/d/wamp64/www/tree/wap/images/newtheme"
files = scan_files(path, None, 'png')
# print(files)
for file in files:
	filename = file
	file_pinyin = lazy_pinyin(filename)
	filename_pinyin = ''.join(file_pinyin)
	try:
		os.rename(str(filename), str(filename_pinyin))
	except Exception as e:
		print(e)