Get external storage path(sd card)



This maybe a special case due to my device speciality.
Anyone know how to read/write to sd card if I already know the external path as /storage/sdcard?
Below line,

let sdCardPath = fs.path.join(android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).toString());

Only will return the device internal storage.

When I tried to ‘hard code’ the folder path, I can see the list by run

let sdPath: fs.Folder = fs.Folder.fromPath("/storage/sdcard1");
            sdPath.getEntities().then(function (entities) {
                entities.forEach(function (entity) {
                    if ( == "DCIM") {
                        var folder: fs.Folder = fs.Folder.fromPath(entity.path);
                        var testFile: fs.File = folder.getFile("test.txt");
                        try {
                                .then(function () {
                                    console.log("aa " + folder.path);
                                        .then(function (content) {
                                        }, function (error) {
                                            console.log("Fail to read" + error);
                                }, function (error) {
                                    console.log("Fail to write " + error);
                        } catch (e) {
                            console.log("Save error " + e);
            }, function (error) {
            } catch (e) {

I can only see all entities name, lastModified… but no write/read allowed.

Fail to write Error: /storage/sdcard1/DCIM/test.txt: open failed: EACCES (Permission denied)```
I already set up external permissions in AndroidManifest.xml. 
And if I can access to sd card path by running android terminal command.


External storage necessarily need not to be SD card, in most devices today the external storage is part of built-in flash drive.

You may try using getExternalFilesDirs, loop through available paths to find your desired storage, you may check whether its removable to make sure its a SD card.


Actually, I can loop it and find sd card path. But it gave me the EACCES (Permission denied) . Any idea?


Are you still using hard coded path? Which device & OS version you are testing it against?


Hi @manojdcoder, I am using android 5.1.1.
getExternalFilesDirs will print out what the manufacturer set up ad “External”.
Unfortunately, getExternalFilesDirs return is internal device storage not sd card.
The way I got that ‘hardcode’ path is to run bash command in terminal.
for those who may have similar issues,@devyaz provided a solution here.


Are you using getExternalFilesDir or getExternalFilesDirs. The second one is going to return array of paths, usually 2nd or later index will be your removable storage.


Neither of them return the sdcard path.
I got what the sdcard path by run adb shell in android terminal.


Thanks @manojdcoder for his help,
For everyone which may have the similar problem as me,
Here is what I did for android device

     let deviceInternalPath = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath();
     let externalath = <any>;
        try {
            let storagePaths: any = externalath.getExternalFilesDirs(, null);
            sdcardPath = storagePaths[1].getAbsolutePath().toString();
        catch (e) {
            console.log("Context compat " + e)

By using ContextCompat.getExternalStoragePublicDirectory(), you can find all external storage. For android 5.1.1, there would be three return values, 1st is device internal, 2nd is sd card, 3rd one is encrypted sd card.