Storing image with consistent filename

:point_right: Note by admin 2021/12/21: On Windows, better use XRUN + VBS file for file operations, instead of XRun+BAT. It is more reliable. (Powershell XRUN Example)


This is a good question. UI.Vision RPA itself has no command to delete files on the hard drive but it has the universal XRun RPA command that allows you to call any script or program. So you can use the XRun command to call a batch file that deletes the file. Of course, batch files are for Windows. If you are on Mac or Linux, you could call a shell or Python script instead. The principle is the same.

So on Windows we have:

Batch file content is just one line:

del "D:\TEST\image1.png"
(This assumes D:\TEST\ is the Chrome download folder)

Macro (batch file location here is d:\\test\\mybatchfile.bat):

{
  "Name": "DownloadImageandDeleteit",
  "CreationDate": "2020-1-18",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://ui.vision/rpa",
      "Value": ""
    },
    {
      "Command": "storeImage",
      "Target": "xpath=//*[@id=\"logo\"]/img",
      "Value": "image1.png"
    },
    {
      "Command": "localStorageExport",
      "Target": "image1.png",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "Wait a bit so we can see the file. Then delete the image.",
      "Value": ""
    },
    {
      "Command": "pause",
      "Target": "3000",
      "Value": ""
    },
    {
      "Command": "XRun",
      "Target": "d:\\test\\mybatchfile.bat",
      "Value": ""
    }
  ]
}

For more flexibility you can even send the image name to the batch file. In this case the last line is:

{
  "Command": "XRun",
  "Target": "d:\\test\\mybatchfile2.bat",
  "Value": "image1.png"
}

and the batch file content is:

del "D:\TEST\%1"

%1 is the batch file command line parameter (“image1.png” on our case).

1 Like