[英]Copy directory from sd card to “files” folder
我想使用cordova-plugin-file將SD卡中的目錄(例如file:///storage/emulated/0/
MyDirectory) files
到files
目錄( data/data/<app-id>/files
), Cordova File API文檔中的一個示例:
function win(entry) {
console.log("New Path: " + entry.fullPath);
}
function fail(error) {
alert(error.code);
}
function copyDir(entry) {
var parent = document.getElementById('parent').value,
parentName = parent.substring(parent.lastIndexOf('/')+1),
newName = document.getElementById('newName').value,
parentEntry = new DirectoryEntry(parentName, parent);
// copy the directory to a new directory and rename it
entry.copyTo(parentEntry, newName, success, fail);
}
我可以找到根據cordova-plugin-file聲明路徑的方法:
var mySrcPath = cordova.file.externalRootDirectory + "MyDirectory";
(對於file:///storage/emulated/0/
MyDirectory)和
var myDesPath = cordova.file.dataDirectory;
(對於data/data/<app-id>/files
)
但是不知道如何為mySrcPath
和myDesPath
聲明DirectoryEntry
對象的代碼
任何人都可以幫助我使上面的示例更清楚地解決我的問題,因為我對javascript的了解不是很好,非常感謝。
在Cordova文檔中 ,您可以找到使用DirectoryEntry的getDirectory函數的快速示例:
function success(parent) {
console.log("Parent Name: " + parent.name);
}
function fail(error) {
alert("Unable to create new directory: " + error.code);
}
// Retrieve an existing directory, or create it if it does not already exist
entry.getDirectory("newDir", {create: true, exclusive: false}, success, fail);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.