Error while doing cd + dir /B *.pdf in Windows

Hi, I’m struggling with an error that should be simple but I can’t see where it is failing. I want to get the list of files in a folder, in Linux (Ubuntu 20) all was simple, I used Run And Return Rc And Output cd ./somefolder/anotherfolder/'Alexander Magno'/lastfolder && ls *.pdf and it return the list of pdf in that folder. BTW, the keyword running this was in root/keywords, therefore, I used the . to return to the root of the bot and then go to somefolder .

The problem is in Windows. When I tried the same it return rc=1 and output was empty. I decided to make the test in cmd, so I run the same code and it returned an error that said that it did not find the folder. I change from simple quotes ( '' ) to double quotes ( "" ) and it worked. I also tried without quotes and worked, it returned the list of pdf inside lastfolder . Then I go to the robot and run it, but the same error appears even if I use double quotes or none. Off course I changed ls for dir (because of Windows), so my keyword was: Run And Return Rc And Output cd ../somefolder/anotherfolder/"Alexander Magno"/lastfolder && dir /B *.pdf . In Windows cmd to return to the previous folder is with .. instead of the . from Linux.

I removed the && dir /B *.pdf part and now output is not empty, it says that it can’t find that path. The same error appears if I removed the quotes. Then I wrote & dir /B *.pdf and output showed: The modifier “*.pdf” is not valid.

Hope someone can help me, thanks.

Edit: it might have to do with Robocorp in Windows, because sometimes it uses a Temp folder instead of where I’m truly am, I will check this now

Before digging into the actual problem (sorry), is there a reason not to use libraries to get the file list e.g.

1 Like

Ohhh, because I did not knew about it :sweat_smile:. And I thought it could be easier with Linux/Windows commands because I know about them.

I found some error like in Windows the paths are with\ instead of Linux’s /. Also it was running in a temp folder so I can said it has everything I wanted there. Now I am using this Run And Return Rc And Output cd ${EXECDIR}\somefolder\anotherfolder\"Alexander Magno"\lastfolder && dir /B *.pdf and works if I don’t write the /B * .pdf

I found that I could use both RPA.FileSystem as OperatingSystem to obtain the files in the directory and filter them. Thanks you so much.

The solution with OperatingSystem would be:

${List}=    List Directory    ${Path}    *.pdf    absolute=False

I still can not understand why it is failing with a command that works in the cmd of Windows, but at least I found a work around thanks to you :grin:.

Edit: I don’t know if select your post as a solution, tho, it solves it using other tools, it does not do it with the a command in the console :sweat_smile: :rofl:

Great call! OperatingSystem library is much better alternative in this case - everything in a single keyword call :+1: