Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
string D = @"C:\The\Search\Path";
// Assumes that the file system is case insensitive
HashSet<string> exts = new HashSet<string>(StringComparer.CurrentCultureIgnoreCase) { "jpg", "jpeg", "png" };
IEnumerable<string> L =
Directory
.EnumerateFiles(D, "*", SearchOption.AllDirectories)
.Where(currentFile => exts.Contains(Path.GetExtension(currentFile)));
L := []string{}
err := filepath.Walk(D, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Printf("failure accessing a path %q: %v\n", path, err)
return err
}
for _, ext := range []string{".jpg", ".jpeg", ".png"} {
if strings.HasSuffix(path, ext) {
L = append(L, path)
break
}
}
return nil
})
import static java.util.Arrays.asList;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
static List<String> L = new ArrayList<>();
record Find(File d, String ... t) {
Find { get(d, t); }
void get(File d, String ... t) {
File a[] = d.listFiles();
if (a == null) return;
for (File f : a)
if (f.isDirectory()) get(f, t);
else asList(t).forEach(s -> {
if (f.getName().endsWith(s))
L.add(f.getName());
});
}
}
L = Dir.glob(File.join("**", "*.{jpg,jpeg,png}"), base: D)