2013-01-22 70 views
2

我想複製一個目錄從一個位置到另一個位置。 我研究,我發現copyTo Api。在該文件中,我發現從DOC簡單的例子如下我可以使用Phonegap/cordova框架複製目錄嗎?

function win(entry) { 
    console.log("New Path: " + entry.fullPath); 
} 

function fail(error) { 
    alert(error.code); 
} 

function copyDir(entry) { 
    var parent = document.getElementById('parent').value, 
     newName = document.getElementById('newName').value, 
     parentEntry = new DirectoryEntry({fullPath: parent}); 

    // copy the directory to a new directory and rename it 
    entry.copyTo(parentEntry, newName, success, fail); 
} 

現在我怎麼迷惑哪裏是源路徑變量,哪些是目標路徑變量? 任何一個可以給我提供這個

回答

6

我希望一個很好的例子,下面可以幫助你理解:

var root; 
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
    function(fileSystem) { 
     root = fileSystem.root; 
     // get the directory we want to get within the root directory 
     var srcDir = 'srcDir'; 
     root.getDirectory(srcDir, {create: false}, getDirectoryWin, getDirectoryFail); 
}); 

// the directory param should be a DirectoryEntry object that points to the srcDir  
function getDirectoryWin(directory){ 
    console.log('got the directory'); 

    // path to the parent directory that holds the dir that we want to copy to 
    // we'll set it as the root, but otherwise you'll 
    // need parentDir be a DirectoryEntry object 
    var parentDir = root; 

    // name of the destination directory within the parentDir 
    var dstDir = 'dstDir'; 

    // use copyWin/copyFail to launch callbacks when it works/fails 
    directory.copyTo(root, dstDir, copyWin, copyFail); 
} 

function getDirectoryFail(){ 
    console.log("I failed at getting a directory"); 
} 

function copyWin(){ 
    console.log('Copying worked!'); 
} 

function copyFail(){ 
    console.log('I failed copying'); 
} 
+1

蒂姆,你知道爲什麼我如果試圖複製「文件中獲取錯誤5:///android_asset/www「目錄?指定相對路徑工作正常,但我需要複製我的cordova index.html旁邊的目錄 – 31415926

相關問題