Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

This is super useful. Any chance for a recursive option to copy directories? #3

mikeymckay opened this Issue Jan 30, 2014 · 7 comments


None yet
3 participants

No description provided.


gkcgautam commented Jan 30, 2014

Good idea. Will add it very soon.

News about recursion?
Great work man!

Copy recursive dir, very dirty, but it works

String startActivity(String assetFile, String destinationDirLocation, String destinationFile) throws IOException {
    File sd_path = Environment.getExternalStorageDirectory();   // Path to the SD Card in the device

    if(destinationDirLocation.indexOf(sd_path.toString())!=0) {
        destinationDirLocation = sd_path+"/"+destinationDirLocation;
    File destDirectory = new File(destinationDirLocation);

    if (destDirectory.exists() && !destDirectory.isDirectory())
        throw new IOException("Can't create directory, a file is in the way");
    if (!destDirectory.exists()) {
        // Create destination directory if it doesn't already exist
        if (!destDirectory.isDirectory()) {
            throw new IOException("Unable to create directory");

    String finalFileName = assetFile;
    if(destinationFile != null && destinationFile.length()>0) {
        finalFileName = destinationFile;

    AssetManager assets = this.cordova.getActivity().getApplicationContext().getAssets();
    String[] list = assets.list(assetFile);
    for(int i=0; i<list.length; i++) {  
        if(list[i].contains(".")) {
            InputStream in = this.cordova.getActivity().getApplicationContext().getAssets().open(addTrailingSlash(assetFile) + list[i]);
            String d = addTrailingSlash(destinationDirLocation) + list[i];
            OutputStream out = new FileOutputStream(d);

            // Transfer bytes from in to out
            byte[] buf = new byte[1024];
            int len; while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
            in.close(); out.close();
        else {
            startActivity(addTrailingSlash(assetFile) + list[i], addTrailingSlash(destinationDirLocation) + list[i], "" );
    return "";

gkcgautam commented Mar 26, 2014

@cagnulein Will improve your code and merge into the plugin whenever i get time.
Can you help me with testing?

No problem :-)


gkcgautam commented Apr 12, 2014

@mikeymckay @cagnulein I have updated the plugin and added support for copying directories.
I have also changed the plugin usage method to make it easier.

Could you please give it a try and report any issues you come across?

@gkcgautam gkcgautam closed this Apr 12, 2014


gkcgautam commented Apr 12, 2014

To be honest, I haven't tested the code! 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment