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?
ppr
(Peter Preuss)
February 23, 2023, 1:15pm
2
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 =
arrPresentFileNames.Except(arrExcelFileNames).toArray
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
And
[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
ppr
(Peter Preuss)
February 23, 2023, 1:31pm
4
Perfect so loop over the calculated list and delete the files
@ppr Is there any wrong with this code?
ppr
(Peter Preuss)
February 23, 2023, 2:32pm
6
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.
Anil_G
(Anil Gorthi)
February 23, 2023, 3:06pm
8
@indrajit.shah
I guess you need to use
arrPresentFileNames.intersect(arrExcelFileNames).toArray
Cheers
1 Like
@ppr
@Anil_G
thank you, I have used the same …intersect was not in my mind…but finally got it
1 Like
system
(system)
Closed
February 26, 2023, 5:14pm
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.