Grab all images from a subdirectory except for a folder

Asked

Viewed 139 times

1

I’m picking up all the photos from a directory and its subsequent ones, but I wouldn’t want it to be the "Backup" folder, as I could do that?

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

I was thinking of using the IndexOf(), but I think that would be a bad optimization because it wouldn’t be easier to take them out than just check if it’s in the right or wrong folder?

1 answer

1


I think the easiest is to use LINQ.

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

I put in the Github for future reference.

The ToArray() may not be necessary there depending on what you 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 you would have to see the criterion of where specifically in the path you might have the "Backup" to consider in the filter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.