Why does a save to sdcard not save to sdcard? And how to check that a file is correctly saved?

401 views
Skip to first unread message

davefinney

unread,
Jan 30, 2017, 8:16:53 PM1/30/17
to DroidScript
When a file is saved to "/sdcard/My App/datastore.txt", it saves to the phones storage (not the sdcard). Why is that?


Also, what is the best way to check a file is correctly saved? I've tried this:

My prog saves the file and then reads the saved file to see if it's the same.

app_path = "/sdcard/My App/datastore.txt"

app.WriteFile( app_path, log );


var checkfile = app.ReadFile( app_path );


if ( log == checkfile )
{

scr9.SetText( "File saved" );

}
else
{

scr9.SetText( "File not saved correctly" );

}

The file has always saved correctly but the check sometimes says the file is saved correctly, and other times says that it has not saved correctly.
Message has been deleted

Symbroson Development

unread,
Jan 30, 2017, 8:35:24 PM1/30/17
to DroidScript
/sdcard/ is an equivalent for /storage/emulated/0 which is your device storage

if you want to acccess your sdcard use /storage/extsdcard.

There are many file functions in the app object. Type app.File in your editor and you will see all file functions in the list on the righthand side, including the FileExists  method

Netpower8

unread,
Jan 30, 2017, 9:32:00 PM1/30/17
to DroidScript
sdcard on android os pertains to the internal sd card... which is correct.

if you want to write to the external sd card... you must specifically indicate an external sd card... but you must check if it exist.


Netpower8

unread,
Jan 30, 2017, 9:46:23 PM1/30/17
to DroidScript
 use these ds command to check sd card

for internal sd card use ==> app.GetInternalFolder();
for external sd card use ==> app.GetExternalFolder();

davefinney

unread,
Feb 5, 2017, 12:51:17 PM2/5/17
to DroidScript
Thanks for replies. I've tested using this. It is run when a button is pressed, "test" starts at 0.
{
    test ++;
    
    if ( test == 1 ) asc9.SetText( app.GetInternalFolder() );
    
    if ( test == 2 ) asc9.SetText( app.GetExternalFolder() );
    
    if ( test == 3 ) app.MakeFolder( app.GetInternalFolder() +"/Atest" );
    if ( test == 4 ) app.MakeFolder( app.GetExternalFolder() +"/Atest" );
    if ( test == 5 ) app.MakeFolder( "/storage/sdcard1/Atest" );
    if ( test == 6 ) app.MakeFolder( "/storage/extsdcard/Atest" );
}

app.GetInternalFolder() returns "/sdcard".
app.GetExternalFolder() returns "/storage/sdcard1".

When run it creates the internal SD card folder, but not the external SD card folder.

I've tried in settings to set "save location" to both "SD card" and "Phone". Either way it creates the internal SD folder, but not the external SD folder.
I've tried dismounting and mounting the SD card but still same result.
The external SD card is there and phone can access files.
It's as though the external SD card is read only to the phone so, to test that, I'll put a file on there and get my app to attempt to read it.

Any other ideas?

davefinney

unread,
Feb 6, 2017, 1:28:04 PM2/6/17
to DroidScript
I've tried checking if folders exist on the external SD card and the app says they don't (when they clearly do).

Does the external SD card have to be "Format as internal" for the app to read it?

If so, surely app.GetInternalFolder() would find them so what would app.GetExternalFolder() be for?

Symbroson Development

unread,
Feb 6, 2017, 1:41:50 PM2/6/17
to DroidScript

Doesnt your "MyFiles" show the current folder path like mine? You should be able to access your sdcard from there and with it the path.


davefinney

unread,
Feb 6, 2017, 7:42:12 PM2/6/17
to DroidScript
Hi SD. Thanks for suggestion. When File Manager opened the choice is "Phone" or "SD Card". When one of these is selected the top just says the same, ie "Phone" or "SD Card".

ps, The phone is a Vodafone Smart Prime 7 (about 6 months old), is this any different to others?

Alan Hendry

unread,
Jun 9, 2020, 12:04:47 PM6/9/20
to DroidScript
Hi,
Following the reference and samples I coded app.MakeFolder("/sdcard/slave");
According to the File Manager app the folder is on Internal Storage

app.MakeFolder( app.GetExternalFolder() +"/slave" );
Doesn't seem to do anything. Do I need additional permissions?

Regards, Alan H

Eevee for the sin

unread,
Mar 28, 2022, 1:46:42 PM3/28/22
to DroidScript
en droid script 2.5 no se puede tener acceso mas allá de la carpeta de la misma aplicacion es una lastima,no se puede crear un reproductor que reproduzca por carpetas

Alan Hendry

unread,
Mar 29, 2022, 5:04:44 PM3/29/22
to DroidScript
HI,
In Android 10+ scoped storage restricts the folders that any app can see.
You should be able to read your own assets and
Internal > Music  using app.GetSpecialFolder("Music)
Similarly for DCIM, Pictures, Movies, Downloads.
For access to the SD card see Sample (touch rocket in top right)
SD card Access 
Changes are coming that will allow "Internal" and "External" to access files.
Regards, ah

Reply all
Reply to author
Forward
0 new messages