如何在 phonegap 中获取 phone 的 sdcard(外部存储卡)的文件夹列表
how to get list of folders of phone's sdcard(External Memory Card) in phonegap
我使用 phonegap 的文件列出 phone 中的所有文件夹,使用此代码。
document.addEventListener("deviceready", makeFileSystemReady, true);
var globalFileSystem;
function makeFileSystemReady(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemError);
}
function onFileSystemSuccess(fs){
globalFileSystem=fs; //Initialized the global file system.
}
function onFileSystemError(){
console.log("Unable to load the file System Plugin");
}
function chooseFromGallery(){
var dirReader = globalFileSystem.root.createReader();
dirReader.readEntries(galleryFiles,galleryFilesErrors);
}
function galleryFiles(entries){
var s = "<p style='color:white'>";
console.log(globalFileSystem.root);
for(var i=0,len=entries.length; i<len; i++) {
//entry objects include: isFile, isDirectory, name, fullPath
s+= entries[i].fullPath;
if (entries[i].isFile) {
s += " [F]";
}
else {
s += " [D]";
}
s += "<br/>";
}
s+="<p/>";
document.getElementById('videoArea').innerHTML=s;
}
function galleryFilesErrors(){
alert("Unable to use the file system !");
}
此代码运行良好,但问题是,我如何获取我的 SD 卡或 Phone.
的外部存储中的文件夹列表
cordoba-plugin-file 的文档具有不同位置的标识符。
https://github.com/apache/cordova-plugin-file
在这种情况下,您希望使用 cordova.file.externalRootDirectory,当您将其传递给 window.resolveLocalFileSystemURL() 时,它将解析为正确的目录条目。
我使用 phonegap 的文件列出 phone 中的所有文件夹,使用此代码。
document.addEventListener("deviceready", makeFileSystemReady, true);
var globalFileSystem;
function makeFileSystemReady(){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemError);
}
function onFileSystemSuccess(fs){
globalFileSystem=fs; //Initialized the global file system.
}
function onFileSystemError(){
console.log("Unable to load the file System Plugin");
}
function chooseFromGallery(){
var dirReader = globalFileSystem.root.createReader();
dirReader.readEntries(galleryFiles,galleryFilesErrors);
}
function galleryFiles(entries){
var s = "<p style='color:white'>";
console.log(globalFileSystem.root);
for(var i=0,len=entries.length; i<len; i++) {
//entry objects include: isFile, isDirectory, name, fullPath
s+= entries[i].fullPath;
if (entries[i].isFile) {
s += " [F]";
}
else {
s += " [D]";
}
s += "<br/>";
}
s+="<p/>";
document.getElementById('videoArea').innerHTML=s;
}
function galleryFilesErrors(){
alert("Unable to use the file system !");
}
此代码运行良好,但问题是,我如何获取我的 SD 卡或 Phone.
的外部存储中的文件夹列表cordoba-plugin-file 的文档具有不同位置的标识符。
https://github.com/apache/cordova-plugin-file
在这种情况下,您希望使用 cordova.file.externalRootDirectory,当您将其传递给 window.resolveLocalFileSystemURL() 时,它将解析为正确的目录条目。