【问题标题】:Can i copy directory using Phonegap/cordova framework?我可以使用 Phonegap/cordova 框架复制目录吗?
【发布时间】:2013-01-22 04:23:48
【问题描述】:

我想将一个目录从一个位置复制到另一个位置。 我对此进行了研究,发现了 copyTo 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,
        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);
}

现在我如何混淆源路径变量和目标路径变量的位置? 谁能给我一个很好的例子

【问题讨论】:

    标签: android ios cordova blackberry cordova-2.0.0


    【解决方案1】:

    希望以下内容对您的理解有所帮助:

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

    【讨论】:

    • Tim,你知道为什么我在尝试复制“file:///android_asset/www”目录时会收到错误 5 吗?指定相对路径效果很好,但我需要复制我的 cordova index.html 旁边的目录
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-27
    • 1970-01-01
    相关资源
    最近更新 更多