首先,需要使用Python的os模块来遍历文件夹,并获取文件夹下的每个文件。接着,通过正则表达式匹配文件名中是否包含系列剧集号码,如果是则将该文件移动到指定目标文件夹中。以下是可能的代码示例:
import os
import re
import shutil
source_folder = '/path/to/source/folder'
target_folder = '/path/to/target/folder'
# 遍历源文件夹
for root, dirs, files in os.walk(source_folder):
for file in files:
# 利用正则表达式匹配文件名中的系列剧集号码
match = re.search(r's\d+e\d+', file.lower())
if match:
# 构建源文件路径和目标文件路径
source_path = os.path.join(root, file)
target_path = os.path.join(target_folder, file)
# 移动文件到目标文件夹
shutil.move(source_path, target_path)
上述代码示例中,os.walk()函数用于遍历整个源文件夹。对于每个文件,使用正则表达式搜索是否包含系列剧集号码。如果找到匹配项,则构建源文件路径和目标文件路径,然后利用shutil库中的move()函数将文件移动到目标文件夹中。