Android-Phoengap-如何从本地存储中获取文件名?

时间:2014-07-10 05:36:29

标签: android cordova filesystems

我是phonegap和android的新手......任何人都可以帮我从目录中检索文件名列表...我查看了phonegap的所有文档,但没有描述我的问题...

1 个答案:

答案 0 :(得分:0)

猜猜你需要这个。

 gotLocalFileSystem : function(fileSystem){ 
             fileSystem.root.getDirectory(Android/data/com.example.example, {create: false, exclusive: false}, getRootDirSuccess, fail);
            },
            getRootDirSuccess: function(dirEntry) {

                    // Get a directory reader
                    var directoryReader = dirEntry.createReader();

                    // Get a list of all the entries in the directory
                    directoryReader.readEntries(dirReadSuccess,fail);
                },

             dirReadSuccess: function( entries ) {
                    if(entries.length > 0){
                        console.log(" No of files Root Directory have : "+entries.length);
                        for (i=0; i<entries.length; i++) {
                            if(entries[i].isDirectory) {
                                var aDirName = entries[i].name; // this will give the entries name
                                 console.log("Entries"+aDirName);
                            }
                        }

                    }else{
                        console.log("Empty Root Directory ");
                        isEmptyRootDir = true;
                    }
                }
    }