午夜精品久久久久久_精品牛牛影视久久精品_东北老夫妇啪啪嗷嗷叫_2022天天躁任你躁

0722-3280566
首頁 > 新聞動態(tài) > 行業(yè)新聞 >

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

程力專汽2024-12-30 23:46:580

# -*- 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, "發(fā)布記錄.csv")
moved_file_path = os.path.join(current_directory, "移動記錄.csv")

# 讀取已經(jīng)移動的文件列表
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])

# 讀取發(fā)布記錄文件并移動文件
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}時出現(xiàn)錯誤:{e}")
else:
print(f"未發(fā)現(xiàn){filename},移動失敗。")

if __name__ == "__main__":
move_files_according_to_record()

 

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