There is such a question ... Suppose I have such a path from the root of the system /sdcard/downloads/ How can I find out if this folder contains any other folders or files or is it empty ..?

    1 answer 1

    To get a list of directory files, use the following example:

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

    If files == null then the directory is empty

    and do not forget permission to read external storage

     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
    • How to check if it is empty? - Vadim
    • File [] files = directory.listFiles (); - if files == null then empty - Sviat Volkov