gpt4 book ai didi

windows - 发生错误时循环的批处理脚本停止

转载 作者:行者123 更新时间:2023-12-03 11:14:31 25 4
gpt4 key购买 nike

我有一个批处理脚本片段,应该对文件夹中的所有文件进行迭代,然后使用curl将它们发送到API。我面临的问题是在迭代过程中,如果一个文件在curl操作过程中产生一些错误,则循环停止(其余文件不会被 curl (如果这是一个技术性的词)。我需要一种方法,如果对文件的curl操作失败,则为循环继续其他文件
以下是我正在使用的代码-

for /R "%SourceDirectory%" %%I in (*.csv) do (
curl --data-binary @%%~fI -H "Content-Type: text/csv" -H "Authorization: Bearer "%secrettoken%"""" %myAPI% >> "%LogFilePath%"
)

最佳答案

使用 for /f + where /r 代替 for /r

@echo off && for /f tokens^=* %%I in (%__APPDIR__%where.exe /r "%SourceDirectory%" *.csv')do >>"%LogFilePath%" (
curl --data-binary @"%%~I" -H "Content-Type: text/csv" -H "Authorization: Bearer" "%secrettoken%" "%myAPI%" )
  • where /?
  • 关于windows - 发生错误时循环的批处理脚本停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59934087/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com