[英]os.rename() for file extensions winerror2
I have been looking for solutions for a while but no luck.我一直在寻找解决方案,但没有运气。 I apologise if this has already been solved.
如果这已经解决,我很抱歉。
Trying to rename file extensions from.ods to.xls across all files in a directory:尝试将目录中所有文件的文件扩展名从.ods 重命名为.xls:
import os
def Convert(dirpath):
for ws in os.listdir(dirpath):
splitfile = os.path.splitext(ws)
os.rename(ws, splitfile[0] + '.xls')
Convert('my_directory')
This returns the error: FileNotFoundError: [WinError 2] The system cannot find the file specified: 'filename_that_exists.ods' -> 'filename_that_exists.xls'这将返回错误: FileNotFoundError: [WinError 2] 系统找不到指定的文件:'filename_that_exists.ods' -> 'filename_that_exists.xls'
Try this might solve your problem试试这个可能会解决你的问题
os.rename(os.path.join(directory,name),
os.path.join(directory,'0'+name))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.