天天看點

android sd卡列目錄檔案,Android的SD卡目錄下的檔案夾名稱清單

android sd卡列目錄檔案,Android的SD卡目錄下的檔案夾名稱清單

Hy everyone...

How can I get names of all folders (not files) in specific directory on SD card? For example all subfolders names in /sdcard/first_level_folder/....

I need folder name, so I can pass complete path (string) to the method which will then compress (zip) it.

Thanks.

解決方案

Step #1: Use Environment.getExternalStorageDirectory() to get the root of external storage. /sdcard/ is incorrect on most devices.

Step #2: Use the appropriate File constructor to create the File object pointing to your desired directory inside external storage.

Step #3: Use Java I/O to find what is in that directory.