Desktop.Windows example for Explorer file select?

Hi just found that this framework also holds a Windows control package! On the calculator example it works fine (although you need to know that whenever you have a non-English Windows the display text will be different… ) but I was wondering whether you can create a script that opens a Windows File Explorer, lets the user browse to a folder, pick a file and return that file name to the script.
Is this possible?

You can probably do that with Windows library also but that does sounds like a file selection dialog case. You could use Dialogs library to ask for file selection.

Couple examples at: https://robocorp.com/docs/libraries/rpa-framework/rpa-dialogs/keywords#add-file-input

Hi @harm.kramer

your way is also possible:

…but I am with @mika …that’s more reliable and faster.

I am looking for the dialog of Windows where you can select a folder (Select Folder) or the dialog where you can select a file (Open File).
Let’s say comparable with the dialog started by RIDE when you do File / Open Directory or File / Open Test Suite.

I tried the example for Dialogs and am wondering what should happen?
I have this:
Create form
Add File Input label=Contract element_id=contract name=contract filetypes=application/pdf target_directory={CURDIR}{/}output
and running says PASS but nothing happens?

And what should be the result of the explorer.exe example? The Explorer opens OK (after I have changed the text to my Dutch text) and I can click folder(s) but after I close that window nothing is returned? What is the 3 it should be looking for?

Edit on the Dialogs solution: the examples are missing the part Request Response hence the script is not waiting and ending before the form can be created/displayed. Adding that part gives me a dialog to select a file to upload which is not entirely what I am looking for. I only want to select a file and get it’s file name and location.

Aaaah…sorry, I got you wrong.
You just want to use a file dialog.

You are actually on the right track but I guess it will not work as long as you do not catch the response:
image

On more example: https://robocorp.com/docs/development-guide/dialogs-assistant/uploading-files

These examples still offer an upload of a file. I merely want the Windows Explorer dialog to Open a file


and return that file name to the script (or the similar dialog to select a folder).
Looking at Dialogs this seems not possible there. So I am looking on how to code that in Desktop.Windows. Problem is that the executable is probably explorer.exe but what arguments to give it?

Naming is bit misleading on those examples. They actually only fetch path to selected file.

Slowly I get the big picture. :blush:

To be honest I never build attended bots with Robocorp so I do not really know everything in detail here but as far as I understood even with the Robocorp Assistant the artifacts will be stored in the cloud.

So, to use Add File Input should be still the right choice.

Please, someone should correct me if I am wrong.

Nevertheless, if you still want to get the filename add a custom python library and use tkinter:
image

Term artifact means objects stored in output folder after task execution has completed. Assistant process works in this sense the same way as workforce processes - if you have objects in the output folder they will be stored as artifacts in the cloud.

But first and foremost, assistants, like workforce processes, handle all files locally. Workforce just might do this in the cloud container or then on the self-hosted environment, like with the Robocorp App.

1 Like

@harm.kramer

Would this work for you ?? I created custom library called ExtendedWindows which will have keyword Get List Items (File Explorer files are of type ListItem in the file list pane) and I added option to return items (files) which are selected by the user.

tasks.robot

*** Settings ***
Library           ExtendedWindows

*** Tasks ***
Checking which files are selected by the user
    [Documentation]    File explorer windowtitle is a folder name
    ${items}=    Get List Items    Pictures
    FOR    ${item}    IN    @{items}
        Log    Item "${item}[name]" is selected
    END

ExtendedWindows.py
from RPA.Desktop.Windows import Windows

class ExtendedWindows(Windows):
    def __init__(self, *args, **kwargs):
        super(ExtendedWindows, self).__init__(*args, **kwargs)

    def get_list_items(self, windowtitle, selected_items=True):
        self.open_dialog(windowtitle)
        _, elements = self.get_window_elements()
        items = []
        for elem in elements:
            if elem["control_type"] == "ListItem" and (
                selected_items and elem["object"].is_selected() or not selected_items
            ):
                items.append(elem)
        return items

Forgive my ignorance but where should I put ExtendedWindows.py to test this in RIDE?

I haven’t used RIDE in years so can’t really say. That library needs to be in a directory which is in pythonpath.

I guess you are not using rcc to run your Robot ?

Nope I am not using rcc. Weird as tasks.robot syntax exactly looks like RIDE syntax.
So I am not sure what to do?

Perhaps I can test something directly from python? But I probably still need to know where to put the ExtendedWindows part?

I really want to test this code but I am clueless how to add it to the packages used by RIDE. Anyone has a suggestion?

Nobody?

Maybe it would help that someone explains or points me to rcc?

Perhaps the folks on #ride channel at RobotFramework Slack would be able to help with placing the library so that RIDE finds it? We don’t seem have many RIDE users around here.

Thanks for the advice. RIDE gets advised on several sites that explain the Robot Framework structure and concept. Are they just wrong or maybe old fashioned? I think RIDE is great!
I found some explanation on RCC: https://github.com/robocorp/rcc

1 Like