Catch all the images in a sub-directory, except for one folder

1

I'm getting all the photos from a directory and its subsequent ones, but I do not like the "Backup" folder, how could I do that?

string[] Arquivos = Directory.GetFiles(PathEx, "*.*", SearchOption.AllDirectories);

I was thinking of using IndexOf() , but I think this would be a bad optimization as it would not be easier to get them out than just check if it's in the right or wrong folder?

    
asked by anonymous 03.12.2017 / 15:44

1 answer

1

I think the easiest is to use LINQ.

var arquivos = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Where(f => !f.Contains("Backup")).ToArray();

ToArray() might not be needed there depending what to do next.

There is a problem there. If the file or other part of the path has the word "Backup", it will filter. If this is inappropriate it would have to see the criteria where specifically in the path you can have the "Backup" to consider in the filter.

    
03.12.2017 / 16:00