2

あるディレクトリをある場所から別の場所にコピーしたい。copyToApiを見つけたということを調べています。そのドキュメントで私は以下のようにドキュメントから簡単な例を見つけました

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

ここで、ソースパス変数と宛先パス変数はどこにあるのか混乱していますか?誰かが私にこれの良い例を1つ提供できますか

4

1 に答える 1

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');
}
于 2013-01-22T23:15:09.420 に答える