Search in array

Hello friends,
@rkelchuri, @Ninett_Panfir, @Rammohan91, @balupad14, @Florent_Salendres, @vvaidya, @Palaniyappan, @ClaytonM, @vvaidya

I need to check if in a folder there are two files with the same name but with two different extensions (.xml and pdf).
How to perform this check?
Can you please help me in giving me a workflow?
Thank you,

1 Like

@CamiCat do you want to work with these two files or only one.if it is one you can give like this
directory.getfiles(“path of the folder”,"*.pdf") if it is xml replace pdf with xml


Hope these steps could help you resolve this
— use assign activity like this
Outpdfilepath = Directory.GetFiles(“yourfolderpath”, ”*.pdf”)

And another assign activity like
Outxmldilepath = Directory.GetFiles(“yourfolderpath”, ”*.xml”)

Where Both the variables are string array

— next use a for each loop and pass the first variable Outpdfilepath as input and change the type argument as string in the property panel of for each loop

— inside the loop use a if condition like this
If the above condition passes it will go rot THEN part which means there is similar filenamed files
Which we can mention In a message box activity
If not will go to ELSE part where we can mention no similar named files in a message box

Simple isn’t it
Hope this would help you
Cheers @CamiCat
If the abo


Sounds like you want to check for duplicates, then do something with it.

Just a simple idea here, but you could get all files for each extension like palaniyappan said, then run them through a loop and match it by the filename to see if it is in both. There’s probably another efficient way, but my brain is not having it.

filesPDF = Directory.GetFiles(folderPath, "*.pdf").Select(Function(f) Path.GetFilenamewithoutextension(f) )
filesXML = Directory.GetFiles(folderPath, "*.xml").Select(Function(f) Path.GetFilenamewithoutextension(f) )

For each f in filesPDF //TypeArgument String
    If filesXML.Contains(f)
      <do something with f + ".pdf" or f ".xml" extension>
1 Like

@CamiCat this will give you an array of string variables that are duplicates.

  1. First create a string array variable I’ll call arrFiles and assign arrFiles = Directory.Getfiles(YourDirectory,"*.*").Where(Function (x) x.EndsWith(".pdf") OrElse x.EndsWith(".xml")).ToArray
  2. For Each file in arrFiles, assign file = Path.GetFileNameWithoutExtension(file)
  3. After For Each loop from step 2 is finished, create another string array variable i’ll called arrDuplicateFiles and assign arrDuplicateFiles = arrFiles.GroupBy(Function(x) x).Where(Function(y) y.Count() > 1).Select(Function(y) y.First).ToArray
  4. Now you have an array of strings that are duplicate file names for .xml and .pdf extensions. You can process them as needed within a for each string activity

Alternative to Step 2 instead of using GroupBy you could just use 2 Where statements instead: Assign arrDuplicateFiles = arrFiles.Where(Function(x) arrFiles.Where(Function(y) x = y).Count() > 1).Distinct().ToArray


Thank you so much @Palaniyappan,

how in case there is a xml file without the pdf ?
inside the loop use a if condition like this
only works if there is a pdf
Thank you.
Cami :slight_smile:

1 Like

That’s a good question
But this expression usually validate only there is a match or not
If there is a match we would get message like “MATCHES”
Whether there is pdf file or not or only XML is there it doesn’t matter
Simple isn’t it
Hope this would help you
cheers @CamiCat

1 Like

Thank you so much @Palaniyappan,

have you got another idea of how to do that?
Thank you,
Cami :slight_smile:

1 Like

Thank you so much @Dave.
How to check both the case of presence of pdf and not xml and the case of presence of xml and not pdf?
Cami :slight_smile:

Oh were we facing any issue with that method
Kindly let know if so

1 Like

@CamiCat - I’m not sure I understand your question?

1 Like