UNIAPP获取本地文件完整教程
loadDir() { let environment = plus.android.importClass("android.os.Environment"); // 判断SD卡是否插入(涉及到SDK的读取,最好先判断SDK是否插入) // environment.getExternalStorageState() === environment.MEDIA_MOUNTED // 获得sd卡根目录 let path = environment.getExternalStorageDirectory().getAbsolutePath(); this.rootPath = path; let lastPath = uni.getStorageSync('lastPath'); // 如果上次打开过目录,则使用上次的路径 if (lastPath) { path = lastPath; } this.getFiles({ fullPath: path + '/Vpi视频', isFile: false }); }, /** * 获取文件夹内容 */ getFiles(file) { if (!file.isFile) { let dirs = [], files = []; let directory = new File(file.fullPath); let arr = directory.listFiles(); arr.forEach(item => { if (!item.isHidden()) { if (item.isDirectory()) { dirs.push({ name: item.getName(), fullPath: item.getPath(), isFile: false, }) } else { // 文件 var filename = item.getName() var parts = filename.split("."); if (parts[1] == 'mp3') { files.push({ title: parts[0], fileUrl: item.getPath(), isFile: true, // 是否是文件 mid: "", epname: "", singer: "", }) } } } }) //console.log(files) this.audioList = files this.getdata(files[0]) if (this.Openif) { this.Openif = false } else { this.Openif = true } } },
[声明]原创不易,请转发者备注下文章来源(hbsjsd.cn)【速建时代】。