I want to get a list of files in the folder

Asked 2 years ago, Updated 2 years ago, 79 views

I'd like to use Cordova api to get a list of files in a folder.

dir.rootDir="a2015/";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0
    , function(fileSystem){
        dir.root=fileSystem.root;
        // Create without folder
        dir.root.getDirectory(dir.rootDir, {create:true, exclusive:false}, function(success){}, fail); 
        // Using the createReader method of the dir object,
        // Create a DirectoryReader Object to Load Files in a Directory
        vardirectoryReader=dir.root.createReader();
        // Read the entries in the directory and pass them to the callback function as an array.
        directoryReader.readEntries(function(success){
            dir.files=success;
        });
    }
);

What should I do if I want to list the files in a2015/ that will be created?Thank you for your cooperation.

monaca cordova

2022-09-29 21:37

1 Answers

I think the objects that should generate DirectoryReader are different.

dir.rootDir="a2015/";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
    function(fileSystem){
        dir.root=fileSystem.root;
        // Create without folder
        dir.root.getDirectory(dir.rootDir, {create:true, exclusive:false},
            function(d){
            // Use the createReader method of the d object.
            // Create a DirectoryReader Object to Load Files in a Directory
                vardirectoryReader=d.createReader();
                // Read the entries in the directory and pass them to the callback function as an array.
                directoryReader.readEntries(function(success){
                    dir.files=success;
                });
            },
            function(err){}
        ); 
    }
);


2022-09-29 21:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.