我有一些代码,可以在文件名的末尾添加单词"_manual"。
我需要更改脚本,以便删除文件名的最后两个字母(ES),然后将它替换为"_ES_Manual"。
例如:AC-5400ES.txt --> AC-5400_ES_manual.txt
如何将该函数整合到此代码中?
如何将该函数整合到此代码中?
folder = r"C:/Documents and Settings/DuffA/Bureaublad/test"
import os # glob is unnecessary
for root, dirs, filenames in os.walk(folder):
for filename in filenames:
fullpath = os.path.join(root, filename)
filename_split = os.path.splitext(fullpath) # filename and extensionname (extension in [1])
filename_zero, fileext = filename_split
print fullpath, filename_zero + "_manual" + fileext
os.rename(fullpath, filename_zero + "_manual" + fileext)