Directory.GetFiles not working

Greetings!

I’m working my way past the Level 1 Foundation training Lesson 2 Control Flow Loops and found a strange situation.

I had already created a project, so to do these lessons, just added a new sequence under the project. In trying to create the example in the Lesson where it gets the files in a directory and puts them in the output, UIPath wasn’t recognizing Directory. It seemed as if it needed a using statement but I could find no place to do that.

After a lot of messing around with it and it not working, even listening to that portion of the training video several times, I went and did it in the main.xaml that is created upon project creation. And it worked. Why? Why does an added sequence/flow not have those basic functions built into them? Is this the case? And if so, how do I add them to a new one I created?

tl;dr How do I include File.IO to sequences or flows other than the first Main in the project?

Thanks!

Jon

Could you provide a screenshot of the error? Not sure if I’m able to follow.

My first guess without full understanding is that the new file you created didn’t have the File.IO namespace imported. In your workflow, next to the variables/arguments tab is a tab called imports. Click that and type in File.IO If my guess is correct then that would solve your issue

1 Like


Including screen shot for clarity.

I saw the Dependencies and Manage Packages but not the Imports down below. That’s what I needed to do.

I’m still having an issue. I was getting the error ? on the Assign items because System.IO was not imported. Must not default on new items but it was included on my Main.xaml page. As soon as I added that into the Imports, the error went away. However, I still get an error.

It doesn’t show the error in the flow but it still errors out on that. Any thoughts?

Thanks for the reply!

Jon

I can only put one image per replay so here is the error image:

Thanks!

Jon

How about System.IO.Directory.GetFiles(x) ?

6 Likes

Hi,im also biginner.
tell you what i understand.

First of all, check out some.
below
1st

2nd

3rd
2019-12-06_070829

thats all.good luck.

@jgoranso Did you convert it to array in the end like Directory.GetFiles("location").ToArray?

Directory.GetFiles() Method is return the path of directory.
so,it has to string.

good regard.

I think what happened was me following the lessons, which were in VB, after having set it up as C#. Now that we can’t use C# at all, the examples should match up better.

Thanks for the replies!

System.IO (not File.IO) worked for me.
Thanks for the solution!

it works.
but I can’t figure out why… because i did not import some package?
seems other C# statements works fine…

Most likely, you have to use the Imports tab below the main designer window to import System.IO. related namespaces.

I don’t import namespaces in if I’m not going to use it extensively across the automation. That’s why I use the fully qualified name.

Below tutorial will help you…