Find specific files in directories and subdirectories except in specific subdirectories

studio

#1

Dear Community,

I use the following command to search all .xaml files in the directory including all subdirectories:

Directory.GetFiles(packageVersionPath,"*.xaml",searchOption.AllDirectories)

However, the code should avoid searching in the subdirectory called “Logs”. Or, alternatively, the code should skip all of the .xaml files that contain the word “MergedFile”. How can I implement either of these two exceptions?

Many thanks
G.


#2

Hey @Gennaro_Bozza

Try This:

Directory. GetFiles(“D:\Samplek”, “*.xaml”, SearchOption.AllDirectories).Where(function(s) NOT s.Contains(“MergedFile”))

use it in For each with type argument String.

Regards…!!
Aksh


#3

SearchOption in GetFiles has only two values- TopDirectoryOnly and AllDirectories. So, no option here to exclude files.

But you can achieve this using LINQ query -

Directory.GetFiles(@"C:\Users\Karthik\Desktop\uipath\ReFrameWork-master\", "*.xaml", SearchOption.AllDirectories)
                        .Where(s => !(s.Contains("MergeData") || s.Contains("\\Log\\")))

#4

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