这些文件包含不同的文件类型。在尝试使用 cmd 更改一堆文件名并使用此类技术后,这并没有改变。找到屏幕截图以便更好地理解。
我从这里使用了这样的Python代码,但它不起作用。 How to change multiple filenames in a directory using Python
最佳答案
您可以使用os
来重命名,并使用glob
来方便地获取文件列表:
import os, glob
def rename(files, pattern, replacement):
for pathname in glob.glob(files):
basename= os.path.basename(pathname)
new_filename= basename.replace(pattern, replacement)
if new_filename != basename:
os.rename(
pathname,
os.path.join(os.path.dirname(pathname), new_filename))
rename('*.XXX', 'XXX', 'YYY')
灵感来自this answer 。
关于python - 如何将文件夹中的所有文件类型更改为特定类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41283195/