Compare folder file names with excel data

Hi there,

I am stuck at a scenario -
I have an excel file with file names and have to compare the names with a folder containing file, If the file is present then delete it and only keep the files which name is not present in the excel list.

@ppr - can this be done with LINQ?

we can at least involve LINQ, if we want to

more sharp to define - what, where to delete (file on filesystem, row in excel)

some hint for the above requirement part.

Find some starter help

Assign Activity:
arrExcelFileNames | String Array =

YourDataTableVar.AsEnumerable.Select(Function (x) x(YourColNameOrIndex).toString.ToUpper.Trim).toArray

Assign Activity:
arrPresentFileNames | String Array =
new DirectoryInfo(YourFolderPath).GetFiles().Select(Function (x) x.Name.ToUpper).toArray

Assign Activity:
arrFileFoundAndNotInExcel |String Array =

As usual, we can do RnD / prototyping within the immediate panel:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum


[CheatSheet] - Filesystem APIs - News / Tutorials - UiPath Community Forum

deleting it from the FileSystem, its about

If the filename is present in the excel file then delete the file from the folder

Perfect so loop over the calculated list and delete the files

@ppr Is there any wrong with this code?

x is FileInfo (check and explore a little bit the attached cheatsheet along within the immediate panel)

When it is about: get the filenames without the extension:

new DirectoryInfo(YourPath).Getfiles().Select(Function (x) Path.GetFileNameWithoutExtension(x.Name)).ToArray
1 Like

@ppr - this is giving the result of file that is unique not the one that needs to be deleted.


I guess you need to use



1 Like

Agreed to @Anil_G

finding the common files

thank you, I have used the same …intersect was not in my mind…but finally got it

1 Like

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