700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python批量重命名指定目录下所有文件的后缀名

python批量重命名指定目录下所有文件的后缀名

时间:2022-08-10 09:45:51

相关推荐

python批量重命名指定目录下所有文件的后缀名

python批量重命名指定目录下所有文件的后缀名

有个需求,需要把某个文件夹下所有后缀名为.abc的更改为.xyz;

#批量重命名指定目录下面所有文件的后缀名。

word_dir为需要更改后缀的文件夹目录

old_ext为原文件最初的后缀名

new_ext为需要更改的新的后缀名

# batch_file_rename.py# Created: 6th August """This will batch rename a group of files in a given directory,once you pass the current and new extensions"""# just checking__author__ = Craig Richards\__version__ = 1.0import argparseimport osdef batch_rename(work_dir, old_ext, new_ext):"""This will batch rename a group of files in a given directory,once you pass the current and new extensions"""# files = os.listdir(work_dir)for filename in os.listdir(work_dir):# Get the file extensionsplit_file = os.path.splitext(filename)# Unpack tuple elementroot_name, file_ext = split_file# Start of the logic

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。