Html Cordova 列出应用程序目录 (WWW) 中的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28937878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cordova list all files from application directory (WWW)
提问by Ravi Mishra
I am using Cordova 4.2.0
with plugins File and media. I have some mp3 files in audio folder inside www
directory. I am able to play files through media plugin using path cordova.file.applicationDirectory+"www/audio/01.mp3"
and trying to get all available files list using window.resolveLocalFileSystemURL
but unable to do so. Please see below code always goes to fail function.
我正在使用Cordova 4.2.0
插件文件和媒体。我在目录内的音频文件夹中有一些 mp3 文件www
。我可以使用路径通过媒体插件播放文件,cordova.file.applicationDirectory+"www/audio/01.mp3"
并尝试使用window.resolveLocalFileSystemURL
但无法获取所有可用文件列表。请参阅下面的代码总是失败的功能。
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory+'/www/audio',
function(dirEntry){
alert('in');
},
fail
);
Please guide me the best way.
请指导我最好的方法。
回答by MrP
You can use this function to get all available files in www/audio/ folder
您可以使用此功能获取 www/audio/ 文件夹中的所有可用文件
function listDir(path){
window.resolveLocalFileSystemURL(path,
function (fileSystem) {
var reader = fileSystem.createReader();
reader.readEntries(
function (entries) {
console.log(entries);
},
function (err) {
console.log(err);
}
);
}, function (err) {
console.log(err);
}
);
}
//example: list of www/audio/ folder in cordova/ionic app.
listDir(cordova.file.applicationDirectory + "www/audio/");