[Help] Error using "file.name.contains()"

Hi all,

I’m new to UiPath and I’m trying to learn how to do simple actions like:

  1. Get directory file names
  2. If file name contains “X” copy it into a folder after renaming
  3. If file name does not contain “X” copy it into a different folder after renaming

Why am I always obtaining the error “name is not a member of System.Array”?

Thanks in advantage,


Your For Each should say “For Each item in files”, or better yet “For Each file in files” (that way the variable is more descriptive). Directory.GetFiles returns an array of String objects so make sure the type property on the For Each is set to String.

Then, inside the loop either item or file will give you the filenames one at a time, depending on what you chose the loop variable to be. You can do item.Contains(“Confirm”) or file.Contains(“Confirm”) to do your filename check.

Hi @alinghi100
you were almost done buddy
but we need small correction to be made
–the first reason the input given to the for each loop is a array of string
so inside the for each loop we will be accessing each value in that array…right
and this individual value is obtained from item the variable in for each loop
so we need to mention as
but we have mentioned as file.name.contains(“Confirm”), which is not right buddy

Kindly try this and let know for any queries and clarfication

Cheers @alinghi100

And even in move file activity mention the source file path as item.ToString and mention the destination path as you want with buddy
Cheers @alinghi100

Hi @Palaniyappan

I got your correction, it makes very sense. But when i run the file i got another error:“for each reference not set to an instance of an object”. :confused:

Change file to files. It looks like you mistyped the array variable name in the For Each activity.

1 Like

can i have a screenshot of that error buddy @alinghi100

@Palaniyappan it worked, the error was unlinked to this function :slight_smile:

Thank you all for the support!

Cheers @alinghi100

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