0

I have a folder in root with some files I want to list but the array returns null:

String path = getenv("EXTERNAL_STORAGE") + "/Files";
File directory = new File(path);
File[] files = directory.listFiles();

Permissions are granted

Kaiser
  • 606
  • 8
  • 22
Mr. M
  • 23
  • 6
  • 2
    Possible duplicate of [How to list files in an android directory?](https://stackoverflow.com/questions/8646984/how-to-list-files-in-an-android-directory) – ravi Oct 31 '19 at 06:59
  • use `Environment.getExternalStorageDirectory()` instead of `getenv` – Droidman Oct 31 '19 at 07:03

1 Answers1

0

First off, you need to use Environment.getExternalStorageDirectory() instead of getenv():

String path = Environment.getExternalStorageDirectory().toString() + "/Files";
File directory = new File(path);
File[] files = directory.listFiles();
for (int i = 0; i < files.length; i++)
    Log.d("Files", "FileName:" + files[i].getName());

But a very important note is the /storage/emulated/0 folder does not really exist. It's what might be called a "symbolic link", or, in simpler terms, a reference to where the real data is stored. That's why your array returns null. You'll need to find the actual physical location on your device where it is stored.

Max Voisard
  • 1,685
  • 1
  • 8
  • 18