Can anybody please help me why i am getting this error?


For additional info,i created this variable FileList as an system.object as variableType,and called this variable below and got this error.
I am just a beginner and its my 6th day learning this RPA tool so can anyone please help?

And moreover i have to use for-Each loop only stead of for each row,here my main motive was to scrap the data from some pdf file and make a datatable at the end

Change the datatype of FileList from System.Object to String Array

grafik
grafik

then press ok, ok

1 Like

But i have to read some pdf files,so will string array be applicable because i think to read pdf files/word document we need to take variabletype as Array of object.

Or if you can clarify this it would be grateful

the returned result of Directory.GetFiles … is a String Array

From official Docu:

This is independend of what files are present in the directory

1 Like

Method GetFiles retuns an array of string
image

Therefore FileList should be of this type
image

I recommend you to watch the IntelliPrompts. It gives useful context related proposals :slight_smile:

Cheers

1 Like

But who is reading documentation these days?
:slight_smile:

Hi ,

Just try attached sequence change the path in assign activity…

#foreachfile
for_each_file_in_folder.xaml (9.7 KB)

1 Like

Hey, Shivam!!

Very cool that you are learning to get help here on the forum! Well, for each is an activity that runs through variables that are iterable! In this case, you created your FileList variable as Object and this variable is not Enumerable to be iterable. By default, the Directory.GetFiles method returns an Array of strings, where each element of this array is a String containing the file path. An array is an iterable variable in for each!

See that we can even work around the case. But it’s not a fancy way.
image
image

So you can change you variable to Array of String!


image

Lets check the output!
image

Any additional questions seek help here! Good luck on your RPA journey!

1 Like

Shivam, the Read Pdf activity takes as input argument the path of the pdf file! The pdf file path is a string, so you can treat the pdf document as your own
own full path. The activity itself is in charge of opening this file with the desired extension and verifies if, in fact, it represents a .pdf file.

Best Regards!

1 Like

The error tells you why. Your variable is System.Collections.IEnumerable but you have the For Each set to Object.

1 Like

Thank you all for helping me,
So i did some changes(was just doing experiment to the statement in the 1st assign activity :sweat_smile:) and as soon as i removed (.toString) from Directory.Getfiles(“path”),it worked because what i was doing was,trying to assign this string to a 1-dimensional array of objects which is not possible with string
Thought to update you all coz you all were helping me.

Thanks
Shivam

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.