Logo

Programming-Idioms

  • Java
  • Kotlin

Idiom #180 List files in directory

Create the list x containing the contents of the directory d.

x may contain files and subfolders.
No recursive subfolder listing.

import java.io.File;
final File directory = new File(d);
final File[] x = directory.listFiles();
import java.io.File;
String x[] = new File(d).list();
#include <dirent.h>
struct dirent ** x = NULL;
int n = scandir (p, &x, NULL, alphasort);

scandir allocates memory and returns the number of entries. each entry must be free'd. See also opendir, readdir and closedir and ftw for recursive traversal.

New implementation...
< >
programming-idioms.org