Python 文件重命名:处理已存在文件
您可以使用'os.path.exists()' 函数来判断文件是否存在,如果存在则可以使用'os.remove()' 函数来删除文件。
下面是一个示例代码:
if os.path.exists(xlsx_file2):
os.remove(xlsx_file)
print(f'已删除 {xlsx_file}')
else:
print(f'错误!文件 {xlsx_file2} 不存在')
原文地址: https://www.cveoy.top/t/topic/p3D4 著作权归作者所有。请勿转载和采集!