How to "get all files from folder" EXCEPT one?

Trying to use “get all files from folder” but want to exclude one or more files from the list. Is there an easy way to add that to the filter property?

Hi @Terry_Marr

Try this linq:

files As List(Of String) = Directory.GetFiles("InputFolderpath", "*.xlsx").Where(Function(file) Not file.EndsWith("Consolidated.xlsx", StringComparison.OrdinalIgnoreCase)).ToList()

Do you have a specific filename which you don’t want to take, give that in place of Consolidated.xlsx.

Hope it helps!!

Hi @Terry_Marr

Try this:

filesToProcess = Directory.GetFiles("YourFolderPath")
                          .Where(Function(file) Not file.EndsWith("excludedFile1.txt") AndAlso
                                                Not file.EndsWith("excludedFile2.txt"))
                          .ToArray()

Regards,

Hi @Terry_Marr

Welcome to the community :blush:

You can simply use an if condition inside your For each files in folder activity. with file name to be ignored and it will work.
condition used in the if activity - Not Path.GetFileNameWithoutExtension(CurrentFile.ToString).Contains(“Name to ignore”)

PFB the screenshot for your reference:

Additionally if you want to filter some file with specific extensions use the filter option in the for each files in folder activity.

Thanks
Biswajeet kumar

@Terry_Marr

In filter you cannot exclude

But inside loop use if condition…if you have list of names can use

Listnames.contains(currentfile.Name)

On then side the files you dont need and other side are files you need

Cheers