0722-3280566
首页 > 新闻动态 > 行业新闻 >

# -*- coding: utf-8 -*-

程力专汽2024-03-29 04:36:230

# -*- coding: utf-8 -*-
import os
import csv
import shutil
import time

def move_files_according_to_record():
current_directory = os.path.dirname(os.path.abspath(__file__))
move_directory = os.path.join(current_directory, "移动")
if not os.path.exists(move_directory):
os.mkdir(move_directory)

record_file_path = os.path.join(current_directory, "发布记录.csv")
moved_file_path = os.path.join(current_directory, "移动记录.csv")

# 读取已经移动的文件列表
moved_files = set()
if os.path.exists(moved_file_path):
with open(moved_file_path, "r", encoding="utf-8") as moved_file:
reader = csv.reader(moved_file)
for row in reader:
moved_files.add(row[0])

# 读取发布记录文件并移动文件
with open(record_file_path, "r", encoding="utf-8", newline='') as record_file:
reader = csv.reader(record_file)
for row in reader:
filename = row[0]
source_file_path = os.path.join(current_directory, filename)
destination_file_path = os.path.join(move_directory, filename)
if os.path.exists(source_file_path) and filename not in moved_files:
try:
shutil.move(source_file_path, destination_file_path)
print(f"已移动文件: {filename}")
# 记录移动成功的文件名
with open(moved_file_path, "a", encoding="utf-8", newline='') as moved_file:
writer = csv.writer(moved_file)
writer.writerow([filename])
except Exception as e:
print(f"移动文件{filename}时出现错误:{e}")
else:
print(f"未发现{filename},移动失败。")

if __name__ == "__main__":
move_files_according_to_record()

 

# -*- coding: utf-8 -*-