输出结果:
编辑日期: 2024-11-28 文章阅读: 次
@author jackzhenguo
@desc
@date 2019/10/5
106 xls批量转换成xlsx
import os
def xls_to_xlsx(work_dir):
"""
传递当前目录,原来后缀名,新的后缀名后,批量重命名后缀
"""
old_ext, new_ext = '.xls', '.xlsx'
for filename in os.listdir(work_dir):
split_file = os.path.splitext(filename)
file_ext = split_file[1]
if old_ext == file_ext:
newfile = split_file[0] + new_ext
os.rename(
os.path.join(work_dir, filename),
os.path.join(work_dir, newfile)
)
print("完成重命名")
print(os.listdir(work_dir))
xls_to_xlsx('./data')
'iotest.txt', 'pyside2.md', 'PySimpleGUI-4.7.1-py3-none-any.whl', 'test.txt', 'test_excel.xlsx', 'ziptest', 'ziptest.zip']