首页 > 解决方案 > 我如何对机器人进行编程以在保存图像或文档之前要求确认?

问题描述

我的桌面上已经有一个名为 ABC.png 的图像并使用机器人我正在从网上下载另一个图像并将其保存在我的桌面上,但在图像保存之前我希望机器人问“你想替换现有图像?” 或者只是我是否想下载图像。我怎么能这样做?

♥image = ♥environment⟦USERPROFILE⟧\Desktop\ABC.png
file.download https://static.makeuseof.com/wp-content/uploads/2016/06/PolkaDots2.jpg filename ♥image
image.findrectangles ♥image
dialog ♥result

标签: automationrpag1ant

解决方案


您可以使用该file.exists命令。♥image这样,您可以检查是否存在与现有目录中同名的文件。

这是一种方法:

♥image = ♥environment⟦USERPROFILE⟧\Desktop\ABC.png
file.exists filename ♥image errorcall downloadFile
dialog.ask message ‴File already exists! Do you want to overwrite the file?‴ result ♥response
if ♥response=="yes"
    call downloadFile 
else if ♥response=="no"
    dialog ‴Operation cancelled, File not downloaded!‴
end

procedure downloadFile
    file.download https://static.makeuseof.com/wp-content/uploads/2016/06/PolkaDots2.jpg filename ♥image
    stop silentmode true
end

这基本上是用命令检查文件是否存在,file.exists如果文件不存在,该命令将引发错误。在errorcall参数中,我们调用该downloadFile过程,因为我们知道该文件尚不存在,因此我们继续下载它。downloadFile程序使用该stop命令来结束机器人的执行,因为我们真的不希望机器人执行任何进一步的代码。(静默模式设置为 true,因为我们不想显示“Process was broken at line x”对话框)。如果文件确实存在,那么我们继续下一行(因为没有发生错误file.existsdownloadFile程序没有被调用),我们打开一个对话框,询问用户是否要下载并覆盖文件。如果输入为“是”,我们通过调用downloadFile或简单地显示消息“操作已取消,文件未下载!”来下载并覆盖文件。在一个对话框中。


推荐阅读