使用Python批量处理文件名的操作示例

2023-05-24T21:48:06

使用Python批量处理文件名的操作示例

遍历文件

import os

file_path = r".\moive"

for root, dirs, files in os.walk(file_path):
    for file_name in files:
        print(file_name)

获取文件后缀

os.path.splitext(file_name)[1]

寻找某个字符的位置

file_name.find('_')

重命名文件

os.rename(root + '/' + file_name, root + '/' + new_name)
# or os.rename(root + '\\' + file_name, root + '\\' + new_name)
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »