简体   繁体   English

如何在phonegap中获取手机sdcard(外部存储卡)的文件夹列表

[英]how to get list of folders of phone's sdcard(External Memory Card) in phonegap

i was using phonegap's file to list all the folders inside the phone using this code. 我正在使用phonegap的文件使用此代码列出电话内的所有文件夹。

      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 !");
  }

This code is working fine, but the problem here is, how can i get the list of folders inside my SD Card or External Storage of my Phone. 这段代码可以正常工作,但是这里的问题是,如何获取SD卡或手机外部存储中的文件夹列表。

The documentation for the cordoba-plugin-file has the identifiers for the different locations. cordoba-plugin-file的文档包含不同位置的标识符。

https://github.com/apache/cordova-plugin-file https://github.com/apache/cordova-plugin-file

In this case you want to use cordova.file.externalRootDirectory which will resolve to the right directory entry when you pass it to window.resolveLocalFileSystemURL(). 在这种情况下,您要使用cordova.file.externalRootDirectory,当将其传递给window.resolveLocalFileSystemURL()时,它将解析为正确的目录条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Android 上使用 Phonegap/Cordova 在外部 sdcard(物理卡)上写入文件? - How to write files on external sdcard (physical card) with Phonegap/Cordova on Android? 如何从外部sdcard和手机存储中获取所有文件(移动存储内部)? - How to get all files from external sdcard and phone storage (internal with mobile memory)? 在Android手机中获取外部SD卡 - Get external sdcard in android phone 从手机的内部存储器+外部SD卡存储器中获取所有图像? - get all the images from Phone's Internal Memory + External SD Card Memory? 获取已安装存储卡的确切路径,但无法获取外部手机存储的确切路径 - Get the exact path of mounted memory card, but not external phone memory 如何获得外部SDCard? - How to get the external SDCard? 如何查找内部电话存储,个人数据,内部SD卡,外部SD卡和内存大小的路径? - How to find Path of Internal Phone Storage, Personal Data, Internal SD Card, External SD Card and Memory Size? 在Samsung S4 Active手机中的外部SD卡上创建目录 - Creating directory on the external sdcard in a Samsung S4 Active phone PhoneGap android应用需要获取外部sdcard路径,但仅返回内部sdcard路径 - PhoneGap android app need to get external sdcard path, but its return only internal sdcard path 如何保存在外部存储卡中? - How to save in external memory card ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM