Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move/copy a file from one folder to other folder in android using phonegap?

In my application on button click i am able to download a file from url into my SDCARD of android whose path is something like "mnt/sdcard/files/data.pdf" and now i want to move/copy this file to some other destination folder using phonegap. Can anyone please help me how to do this in phonegap?

I have a pdf file in path "mnt/sdcard/files/data.pdf" and i want to move that pdf file to new path "mnt/sdcard/download/data.pdf" anyone please help me.

like image 210
android phonegap Avatar asked Sep 14 '12 05:09

android phonegap


People also ask

How do I move files from one folder to another?

You can move a file or folder from one folder to another by dragging it from its current location and dropping it into the destination folder, just as you would with a file on your desktop. Folder Tree: Right-click the file or folder you want, and from the menu that displays click Move or Copy.

How do I copy files in Android 11?

Okay, so we have the AOSP files app open. Copying or moving data out of the "Android/data" folder is, thankfully, pretty simple. Simply navigate to the folder as usual, long-press on the content you want to select, then go to the three-dot menu in the upper-right and choose either "Copy to..." or "Move to...".


1 Answers

Assuming you are actually using Cordova, check FileEntry, which has methods named moveTo and copyTo.

Be aware that the file systems API are a callback hell.

One quick example from the docs cooked overlooking the docs:

var fail = function(err) { console.log(err) }
window.resolveLocalFileSystemURI("file:///example.txt", function(file) {
   window.resolveLocalFileSystemURI("file:///directory-to-move-to", function(destination) {
             file.moveTo(destination,"example.txt");
   },fail)
},fail);

I skipped the error handling functions for clearness, suppose it works without it.

like image 121
pedrofurla Avatar answered Nov 01 '22 11:11

pedrofurla