How to fix this error (1-dimensional array of String cannot be converted to String)

Hello,

I’m getting this error when using the .GetFiles method on an assign activity.

Assign Activity
FilesCheck = directory.GetFiles(Path_Files.ToString)

Path_Files = is a value from an excel file that is an output of a “Get Row Item” activity

The Error -
Complier Error(s) encountered processing expression “directory.GetFiles(Path_Files)”.
Value of type ‘1-dimensional array of String’ cannot be converted to ‘String’

Thanks,
Paolo

Hi @pcats,

Directory.GetFiles() returns String data.

Therefore change the variable type of FilesCheck to String.

Regards,
Rahamat

2 Likes

Hi,

Please check the type of FilesCheck variable, it should be an array of string, because “directory.GetFiles” will return a 1D array of all the retrieved file names.

Thanks,
Sarthak

2 Likes

but how? I thought I you typed (filename.ToString) it converts it to a string or is that a 1D String?

Well, in the original post you have this:
FilesCheck = directory.GetFiles(Path_Files.ToString)

And as such, the original poster got an error because they were trying to assign the output of Directory.GetFiles method (which is an Array of String) to a variable FilesCheck which was probably defined as simple String.

In simple terms, the variable in the left must have the same type as the expression on the right :slight_smile:

I am new to UIpath. I am getting this error on a simple data move program. Please advise

Flowchart.xaml: Compiler error(s) encountered processing expression “directory.GetFiles(Sourcepath)”.
Value of type ‘1-dimensional array of String’ cannot be converted to ‘String’.

1 Like

directory.getfiles returns an array. You are trying to assign that array to a string variable, or use the array somewhere a string is required.

I am trying to assign it to a variable Numberoffiles with variable type as String. Using Assign activity in UiPath