logo

0722-3280566

语言切换

标签图

  • 微信二维码
# -*- coding: utf-8 -*-

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

本文摘要: #-*-coding:utf-8-*-importosimportcsvimportshutilimporttimedefmove_files_accordin

正文

# -*- 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 -*-
(图1)



评论区

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

    清障车小王子

    2024-03-01 21:10:22

    感谢销售王经理的支持,合作的很愉快

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

    Eleanor Smith

    2023-09-02 16:39:55

    I am from Saudi Arabia, and Chenglí not only delivered 150 vehicles to us on time but also sent a dedicated technical team to provide on-site training. I am very thankful to China! I am very grateful to Chenglí Company! I love China; they are very welcoming, and I also love Chinese cuisine.

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

    j***z

    2023-08-24 10:57:19

    点赞!!!!

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

    我是一条鱼

    2023-02-09 18:57:19

    给程力服务点赞! 在这个项目中代理了程力产品,终端客户在西藏 厂家专门安排了一个团队做全程的技术、招投标支持服务 做专用汽车项目选程力就对了

我要评论

热门推荐