2013-01-22 1 views
2

한 위치에서 다른 위치로 하나의 디렉토리를 복사하고 싶습니다. 내가 찾은 것에 관한 연구 copyTo Api. 이 문서에서 나는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 "디렉토리? 상대 경로 지정은 잘 작동하지만 코드 바 옆에있는 디렉토리를 복사해야합니다. index.html – 31415926

관련 문제