有可能是相對路徑有誤導致閃退,請你幫我更正src_path = r"Z:\看板v2" dst_path = r"\\pcq-smt-ftp01\smt$\CQ SMT-單板測試課\6.制程組--Junliang\看板源數據\治具NTF" src_folder = r"Y:\iplas\Robot_Log\SMT" dst_folder = r"\\pcq-smt-ftp01\smt$\CQ SMT-單板測試課\6.制程組--Junliang\看板源數據\治具NTF"
时间: 2023-06-30 10:27:28 浏览: 70
根据您提供的路径信息,我可以看出您的源路径和目标路径都是网络共享路径。您需要注意以下几点:
1. 确认网络共享路径是否已经正确映射
2. 检查源路径和目标路径是否均可以被当前用户访问
3. 确认路径中的反斜杠是否正确转义,可以使用原始字符串表示法(在路径字符串前加上'r')来避免反斜杠转义问题
根据您提供的路径信息,可以对应以下代码:
```python
src_path = r"Z:\看板v2"
dst_path = r"\\pcq-smt-ftp01\smt$\CQ SMT-單板測試課\6.制程組--Junliang\看板源數據\治具NTF"
src_folder = r"Y:\iplas\Robot_Log\SMT"
dst_folder = r"\\pcq-smt-ftp01\smt$\CQ SMT-單板測試課\6.制程組--Junliang\看板源數據\治具NTF"
```
请注意,在路径字符串前加上'r'表示使用原始字符串表示法。如果仍然无法正常运行,请检查路径映射、用户权限等问题。
相关问题
dst_img = src_img[top:bottom, left:right]这行代码是什么意思
这行代码是用来从原始图像 `src_img` 中裁剪出一个子图像的操作。其中 `top`、`bottom`、`left` 和 `right` 是四个整数,表示子图像的上下左右四条边与原始图像的上下左右四条边之间的相对位置关系。具体来说,`top` 表示子图像的上边缘与原始图像的上边缘之间的距离;`bottom` 表示子图像的下边缘与原始图像的上边缘之间的距离;`left` 表示子图像的左边缘与原始图像的左边缘之间的距离;`right` 表示子图像的右边缘与原始图像的左边缘之间的距离。裁剪出来的子图像会被保存到一个新的数组 `dst_img` 中,并返回给调用者。
請你幫我添加一段代碼,需要實現運行完成后輸出當前的額時間import os import datetime import time # 原文件夹路径和目标文件夹路径 src_path = r"Z:\看板v2" dst_path = "D:\測試log" # 获取今天日期,并格式化成指定的形式 today = datetime.date.today() formatted_today = today.strftime("%Y%m%d") # 构造目标文件的完整路径 dst_file = os.path.join(dst_path, f"當天測試log.txt") # 记录程序开始运行时间 start_time = time.time() # 遍历原文件夹,查找当天日期的 TXT 文件 txt_files = [] for root, dirs, files in os.walk(src_path): for file in files: if file.endswith(".txt") and file.startswith(formatted_today): txt_files.append(os.path.join(root, file)) print(f"共找到 {len(txt_files)} 个符合条件的 TXT 文件!") # 如果找到符合条件的 TXT 文件,则将它们合并到目标文件中 if len(txt_files) > 0: with open(dst_file, "w", encoding="utf-8") as f: for src_file in txt_files: # 读取 TXT 文件的内容,并写入目标文件中 with open(src_file, "r", encoding="utf-8") as txt_file: content = txt_file.read() f.write(content) # print(f"文件 {src_file} 已合并到目标文件中!") print(f"{len(txt_files)} 个符合条件的 TXT 文件已成功合并到目标文件 當天測試log.txt 中!") else: print("未找到符合条件的 TXT 文件!") # 计算程序运行时间 end_time = time.time() run_time = end_time - start_time print(f"程序运行时间:{run_time:.2f} 秒")
這是您需要的代碼:
```
import os
import datetime
import time
# 原文件夹路径和目标文件夹路径
src_path = r"Z:\看板v2"
dst_path = "D:\測試log"
# 获取今天日期,并格式化成指定的形式
today = datetime.date.today()
formatted_today = today.strftime("%Y%m%d")
# 构造目标文件的完整路径
dst_file = os.path.join(dst_path, f"當天測試log.txt")
# 记录程序开始运行时间
start_time = time.time()
# 遍历原文件夹,查找当天日期的 TXT 文件
txt_files = []
for root, dirs, files in os.walk(src_path):
for file in files:
if file.endswith(".txt") and file.startswith(formatted_today):
txt_files.append(os.path.join(root, file))
print(f"共找到 {len(txt_files)} 个符合条件的 TXT 文件!")
# 如果找到符合条件的 TXT 文件,则将它们合并到目标文件中
if len(txt_files) > 0:
with open(dst_file, "w", encoding="utf-8") as f:
for src_file in txt_files:
# 读取 TXT 文件的内容,并写入目标文件中
with open(src_file, "r", encoding="utf-8") as txt_file:
content = txt_file.read()
f.write(content)
# print(f"文件 {src_file} 已合并到目标文件中!")
print(f"{len(txt_files)} 个符合条件的 TXT 文件已成功合并到目标文件 當天測試log.txt 中!")
else:
print("未找到符合条件的 TXT 文件!")
# 计算程序运行时间
end_time = time.time()
run_time = end_time - start_time
# 输出程序运行时间
print(f"程序运行时间:{run_time:.2f} 秒")
```
運行完成後,程序會輸出當前的額時間。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)