Unzip shared file

83 views
Skip to first unread message

Ken Swindell

unread,
Jan 10, 2023, 8:17:27 AMJan 10
to DroidScript
Can shared zip files be extracted to a Local Folder? I can navigate to the file and open it with other apps like X- plorer and google files. X-plorer lists droidscript as a compatible file when i hover it.

// Work with SW Maps App (a gis data collection app) shared cvs zipped files
// goal is to access a comma deliminated list of points

// from SW Maps app a project is shared as cvs
// with droidscript, this porduces a zip file in a SW local Export folder
// then the code below is run


//Called when application is started.
function OnStart()
{
    //Create a layout with objects vertically centered.
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" )
    //Create a text label and add it to layout.
   
    txt = app.CreateText( "shared cvs",-1,.9,"Mulitline")
    txt.SetTextSize( 10 )
    lay.AddChild( txt )
   
    txt1 = app.CreateText( "content",.9,-1,"Mulitline")
    txt1.SetTextSize( 10 )
    lay.AddChild( txt1 )
   
   
   
    //Add layout to app.    
    app.AddLayout( lay )
   
    extractpath = '/sdcard/mappoints'
    zipfile = app.GetSharedFiles();
       
    txt.SetText(zipfile) //
    // txt is as expected: /external_file/Android/media/np.com.softwel.swmaps/Export/Project 1 CVS.zip
       
    app.UnzipFile(zipfile,extractpath)
    //WARNING: App.UnzipFile() failed! (/external_files/Android/media/np.com.softwel.swmaps/Export/Project 1 CSV.zip: open failed: ENOENT (No such file or directory)
 

}

Right2TheV0id

unread,
Jan 10, 2023, 11:45:57 AMJan 10
to DroidScript
I just tried replacing /external_files/ by /sdcard/ and it seems to work.
Here the version I used:

function OnStart()
{

    lay = app.CreateLayout( "Linear", "VCenter,FillXY" )
    lay.SetChildMargins( 0, 10, 0, 10, "dip" )
   
    txt = app.CreateText( "shared cvs:",.9,-1,"Multiline")
    txt.SetTextSize( 14 )
    lay.AddChild( txt )
   
    txt1 = app.CreateText( "content:",.9,-1,"Multiline")
    txt1.SetTextSize( 14 )
    lay.AddChild( txt1 )

   
    app.AddLayout( lay )
   
    extractpath = "/sdcard/mappoints"
    zipfile = app.GetSharedFiles()
       
    txt.SetText( txt.GetText() + "\n" + zipfile )

    // txt is as expected: /external_file/Android/media/np.com.softwel.swmaps/Export/Project 1 CVS.zip
   
    if( zipfile )
    {
        zipfile = zipfile[0].replace( "/external_files/", "/sdcard/" )

        app.UnzipFile(zipfile,extractpath)
        //WARNING: App.UnzipFile() failed! (/external_files/Android/media/np.com.softwel.swmaps/Export/Project 1 CSV.zip: open failed: ENOENT (No such file or directory)
       
        file = app.ListFolder( extractpath, ".csv", 1, "FullPath" )[0]
        txt1.SetText( txt1.GetText() + "\n" + app.ReadFile( file ) )
    }
}


Ken Swindell

unread,
Jan 20, 2023, 4:03:08 PMJan 20
to DroidScript
Thanks so much for looking at this. When I pasted your code and ran it i get this in the debug window:

  • -> /external_files/Android/media/np.com.softwel.swmaps/Export/Project 1 CSV.zip
  • Txt.GetText( )
  • -> shared cvs:
  • Txt.SetText( shared cvs: /external_files/Android/media/np.com.softwel.swmaps/Export/Project 1 CSV.zip )
  • App.UnzipFile( /sdcard/Android/media/np.com.softwel.swmaps/Export/Project 1 CSV.zip, /sdcard/mappoints )
  • WARNING: App.UnzipFile() failed! (/storage/emulated/0/Android/data/com.smartphoneremote.androidscriptfree/files/Android/media/np.com.softwel.swmaps/Export/Project 1 CSV.zip: open failed: ENOENT (No such file or directory))
  • App.ListFolder( /sdcard/mappoints, .csv, 1, FullPath )
  • -> []
  • Txt.GetText( )
  • -> content:
  • App.ReadFile( , )
  • WARNING: App.ReadFile() failed! (/storage/emulated/0/Android/data/com.smartphoneremote.androidscriptfree/files/DroidScript/copyonopen/undefined: open failed: ENOENT (No such file or directory))
  • Txt.SetText( content: )

Right2TheV0id

unread,
Jan 22, 2023, 7:46:32 PMJan 22
to DroidScript
This is obviously a "scoped storage" thing.
It works well on Android versions < 10, then it's become really complicated.

Apparently DroidScript has difficulties to open non media files in Android 10+ versions.
The closest I was able to get is to rename the ".zip" file in ".zip.png" with a file explorer app and to share it with DroidScript.
Then you can copy it in "/sdcard/mappoints", rename it to remove the ".png" and extract it.

So it requires additional steps, plus the shared path will differ from one app to another which can be difficult to handle:
Sharing with SW Maps: "/external_file/Android/media/np.com.softwel.swmaps/Export/Project 1 CVS.zip"
Sharing with CX Explorer: "/root/storage/emulated/0/Android/media/np.com.softwel.swmaps/Export/Project 1 CSV.zip.png"
Sharing with Google Files: "/1/file:///storage/emulated/0/Android/media/np.com.softwel.swmaps/Export/Project%201%20CSV.zip.png"

Maybe I'm missing a simple solution as I don't master the scoped storage and SAF things.

Димыч Вакулин

unread,
Jan 23, 2023, 3:00:04 AMJan 23
to DroidScript
At the moment, the Uri scheme="file" is outdated, and everyone uses scheme="content". In this scheme, you will not get the true path to the file, there is a fileprovider mechanism. I haven't used DS for a long time and don't know the details, ask Dave how to use it for a DS user.

понедельник, 23 января 2023 г. в 03:46:32 UTC+3, Right2TheV0id:

Ken Swindell

unread,
Jan 27, 2023, 7:36:38 AMJan 27
to DroidScript
Thanks for the info.
Reply all
Reply to author
Forward
0 new messages