32 lines
834 B
Python
32 lines
834 B
Python
import shutil
|
|
import os
|
|
|
|
# 源目录和目标目录
|
|
src_dir = "UI/dist"
|
|
dst_dir = "server/wwwroot"
|
|
|
|
# 确保目标目录存在
|
|
os.makedirs(dst_dir, exist_ok=True)
|
|
|
|
# 复制文件
|
|
try:
|
|
# 删除目标目录中的旧文件
|
|
for item in os.listdir(dst_dir):
|
|
item_path = os.path.join(dst_dir, item)
|
|
if os.path.isdir(item_path):
|
|
shutil.rmtree(item_path)
|
|
else:
|
|
os.remove(item_path)
|
|
|
|
# 复制新文件
|
|
for item in os.listdir(src_dir):
|
|
src_path = os.path.join(src_dir, item)
|
|
dst_path = os.path.join(dst_dir, item)
|
|
if os.path.isdir(src_path):
|
|
shutil.copytree(src_path, dst_path)
|
|
else:
|
|
shutil.copy2(src_path, dst_path)
|
|
|
|
print("文件复制成功!")
|
|
except Exception as e:
|
|
print(f"复制文件时出错: {e}") |