上传文件至 python

Signed-off-by: Carol <gitea@noreply.cnkj.site>
This commit is contained in:
Carol 2023-08-31 20:18:08 +08:00
parent c2fcfa50b1
commit 3b81846df5

51
python/changeFileName.py Normal file
View File

@ -0,0 +1,51 @@
# -*- coding=utf-8 -*-
# @Time : 2023/1/14 13:22
# @Author : LXW
# @File : changeFileName.py
import os
import re
import sys
def change_file_suffix(input_file_path):
for parent_path, dir_path, filenames in os.walk(input_file_path):
for filename in filenames:
base_name = os.path.basename(parent_path)
result = re.search(base_name, filename)
if None is not result and not str(filename).endswith(".vsmeta"):
print(filename)
new_filename = filename.split(base_name + ".")[1]
os.rename(os.path.join(parent_path, filename), os.path.join(parent_path, new_filename))
def delete_files(input_file_path):
for parent_path, dir_path, filenames in os.walk(input_file_path):
for filename in filenames:
if str(filename).endswith(".vsmeta"):
os.remove(os.path.join(parent_path, filename))
def change_naruto(input_file_path):
for parent_path, dir_path, filenames in os.walk(input_file_path):
for filename in filenames:
base_name = os.path.basename(parent_path)
result = re.search(base_name, filename)
if None is not result and not str(filename).endswith(".vsmeta") and not str(filename).endswith(".srt") and not str(filename).endswith(".ass"):
print(filename)
first_split = filename.split("[西行纪][The Westward][")
if len(first_split) > 1:
# number = first_split[1].split(".")[0].replace(" ", "")
# new_filename = base_name+"."+number+".mp4"
number = first_split[1]
new_number = number.split("]")[0]
new_filename = "西行纪.The Westward.S01E" + new_number + ".mp4"
os.rename(os.path.join(parent_path, filename), os.path.join(parent_path, new_filename))
if __name__ == '__main__':
# __input_file_path = sys.argv[1]
__input_file_path = "F:\download\西行纪"
change_naruto(input_file_path=__input_file_path)
delete_files(input_file_path=__input_file_path)