Storing image with consistent filename

Hello!

Just started on UI vision and still figuring out the basics.

I am download a captcha from a website and then upload it to an other website. All working without problems, except, when I do this in al loop, the first image has the filename as specified (captcha.png), the second on the filename with an 1 behind it (captcha(1).png). How can I make sure the old filenames are overwritten?

I have tried many approaches and also searched a way to delete a local file, but haven’t had any succes.

Please help!

Thanks,

Katertje.

1 Like

: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

Thanks for you reply.

This seems simple and exactly what I need. But running Mac OS. I made a shellscript and tried to run that with the XRun command. But all I get is the error “Dom not found”. I have tried the XRun command running calculator (copied it from an example on the UI vision site), but even then I get an “Dom not found” error…

Any ideas on this?

Yeehaa, working. A restart of firefox / RPA did the trick. Working like a charm now. Thanks!!

Great to hear! Meanwhile I tested on the Mac as well and it worked fine for me, too. Here is what I used:

Shell file content:

#!/usr/bin/env bash
rm /Users/uli/Desktop/a1/image1.png

XRun command:
xrun | /Users/uli/Desktop/a2.sh

Also, I needed to change the permissions. On the terminal run:

chmod +x your_bash_file (here a2.sh)

Hi @ulrich,

I have a similar shell script which I’m running on Mac but it doesn’t seem to be executed when I’m using XRun.

    {
      "Command": "XRun",
      "Target": "/Users/jpnd/Desktop/ivpn_connect.sh",
      "Value": ""
    }

There are no errors on the UI.Vision RPA window but the script wasn’t executed.
Any inputs on this?

logs:
[status]
Playing macro xrun
[info]
Executing: | XRun | /Users/jpnd/Desktop/ivpn_connect.sh | |
[info]
Macro completed (Runtime 0.39s)

  • Executing: | XRun | C:\Users\a\Downloads\Demo.bat | |

  • [info]

Macro completed (Runtime 0.20s)

bat file didnt opened

bat file content
timeout 6

Instead of using a BAT file, can you test with a VBS or Powershell script? This usually works better.

Example:

XRUN | Powershell.exe | -executionpolicy bypass -file C:\Users\qa2\Desktop\lockscreen1.ps1

Note: make sure to add -executionpolicy bypass, otherwise the script does not start.