copy file to "document" folder

143 views
Skip to first unread message

Matteo De vita

unread,
Sep 30, 2025, 9:37:02 AMSep 30
to DroidScript
Good morning, I'm writing an app to create a gcode file from an image captured by the camera. My problem is copying the output file to the "document" folder. Could you please tell me how to copy a file from the app's internal folder to the Android "document" folder? I'm using Motorola Android 14. Thanks

Alan Hendry

unread,
Sep 30, 2025, 12:39:29 PMSep 30
to DroidScript
HI,
See app.GetSpecialFolder
Images would normally go to "Pictures"
(but you can try "Documents")
You probably need to write to a subfolder
For Android 10+ you probably have scoped storage 
and may need to look at CheckPermission and GetPermission
Regards, ah

Matteo De vita

unread,
Oct 1, 2025, 3:29:12 AMOct 1
to DroidScript
Good morning,
I tried this simple one, but it doesn't work. Any suggestions?

function OnStart()

{

    var check = app.CheckPermission( "Camera,ExtSDcard,Network,Storage" );

    alert(check)

          if( check )

    {

        app.GetPermission( check, PermissionResult );

    }

    else alert( "everything ok!" ); 

     fidr =app.GetSpecialFolder("Pictures")

             alert(fidr)

          app.WriteFile(fidr+"/file.txt")

          alert(app.FileExists(fidr+"/file.txt"))

   

}

 

function PermissionResult( ungranted )

{

    alert( "ungranted: " + ungranted );

}


Cemal

unread,
Oct 1, 2025, 3:36:19 AMOct 1
to DroidScript
You can try this example, but remember that it only allows Documents folder (maybe DCIM and Pictures folder too).

const workingFolder = "/Internal/Documents/MyData";

function OnStart() {
lay = app.CreateLayout("Linear", "VCenter,FillXY");

txt = app.AddText(lay, "The file was not read");

// Check if the necessary permissions are granted.
if (checkPerm()) {
read();
write();
} else {
// If permissions are not granted, request them.
requestPerm();
}

app.AddLayout(lay);
}

// Check if the required permissions are granted.
function checkPerm() {
return !!app.CheckPermission(workingFolder);
}

// Request permissions from the user.
function requestPerm() {
// Show a popup to inform the user that permission is required.
app.ShowPopup("Allow access to the Documents folder.", "Permission required");

// Request permission to access the internal storage.
app.GetPermission("internal", OnPermission);
}

// Handle the result of the permission request.
function OnPermission(path) {
// If permission is not granted, show an alert.
if (!path) {
app.Alert("Permission not granted!");
} else if (!checkPerm()) {
// If the permission is granted but the folder is not selected, alert the user.
alert("Make sure to select the Documents folder.");
requestPerm(); // Request permission again.
} else {
// If permissions are granted and folder is selected, proceed to write and read.
write();
read();
}
}

function write() {
// Create content with the current date and time.
const content = "Last visit: " + new Date().toLocaleString();
// Ensure the working folder exists.
app.MakeFolder(workingFolder);
// Write the content to a file named "test.txt" in the working folder.
app.WriteFile(workingFolder + "/test.txt", content);
}

function read() {
// Read the content of the file "test.txt".
const content = app.ReadFile(workingFolder + "/test.txt");
txt.SetText(content);
}

Matteo De vita

unread,
Oct 1, 2025, 5:13:19 AMOct 1
to DroidScript

Hi, Thanks for the suggestion.
I tried... it gives me 2 errors.
App.checkPermission(/internal/documents/myData) WARNING: App.checkPermission() failed!(Starage access is a Premium feature!)

App.GetPermission(internal,OnPermission)   WARNING:   App.GetPermission() failed!(Starage access is a Premium feature!) At this point, to copy files outside the app folder to "document" or "image," is it necessary to upgrade to the premium version?

Alan Hendry

unread,
Oct 1, 2025, 12:01:32 PMOct 1
to DroidScript
HI,
Hmm
Check and Get Permissions don't show as Premium in the docs 
Here's my code to test writing to different folders
It should tell you if the folder exists, and say Works! if it can write there
(Android 15 I can only write to documents and its subfolders)
Regards, ah

_AddPermissions("Storage")
_AddPermissions("extsdcard")

function OnStart() {

   alert("scoped storage "+ app.IsScoped())

/*
   doit(app.GetPrivateFolder(), "gpf.jpg");
   doit(app.GetPrivateFolder("Pictures"), "gpfp.jpg");
   doit(app.GetPrivateFolder("", "External"), "gpfe.jpg");
   doit(app.GetPrivateFolder("Pictures", "External"), "gpfpe.jpg");

   doit(app.GetInternalFolder(), "gi.jpg");
   doit(app.GetExternalFolder(), "ge.jpg");

   doit(app.GetPath(), "gp.jpg");
   doit(app.GetAppPath(), "gap.jpg");
*/
   doit(app.GetSpecialFolder("Pictures"), "gsfp.jpg");
   doit(app.GetSpecialFolder("Pictures")+"/folder", "gsfpf.jpg");
   doit(app.GetSpecialFolder("Documents"), "gsfd.jpg");
   doit(app.GetSpecialFolder("Documents")+"/folder", "gsfdf.jpg");
   doit(app.GetSpecialFolder("Downloads"), "gsfxf.jpg");
   doit(app.GetSpecialFolder("Downloads")+"/folder", "gsfxf.jpg");

//   doit("r", "r.jpg");

//   doit("/Storage/files/Pictures", "ss.jpg");

}

function doit(p, f) {
   app.MakeFolder(p)
   alert("folder "+f+" created "+app.FolderExists( p ))
   fn = p + "/" + f
   app.WriteFile(fn, "Works!")
   alert(fn + "\n" + app.ReadFile(fn))
   app.DeleteFile( fn )
}

Alan Hendry

unread,
Oct 2, 2025, 3:57:27 PMOct 2
to DroidScript
HI,
I seem to recall that if you aren't Premium
then Get and Check Permissions 
are restricted to "extsdcard"

Alan Hendry

unread,
Oct 5, 2025, 6:12:26 AM (13 days ago) Oct 5
to DroidScript
HI,
Also see the SAF example
Touch top-right icon, then rocket, search for storage (tick general).
Regards, ah
Reply all
Reply to author
Forward
0 new messages