在captureSuccess中移动和重命名文件 [英] In captureSuccess move and rename the file

查看:180
本文介绍了在captureSuccess中移动和重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个智能手机将音频文件保存在不同的文件夹中,一个在root和其他在根/音频文件夹。我想做的是,每当captureAudio成功,我不想保存到默认文件夹(音频或根)。我想创建一个名为Test(example)的文件夹,并根据我的需要重命名音频文件。这是我到目前为止,并给我错误关于[对象] [对象]没有方法moveTo;

I have 2 smartphones that saves audio file in different folder, one in the root and other in root/Audio folder. What I'm trying to do is, whenever the captureAudio is success, I don't want to save it into default folder(Audio or root). I wanted create a folder called Test(example) and rename the audio file into according to my needs. This is what I got so far, and gives me error about [Object] [Object] has no method moveTo;

    function captureAudio() {
// Launch device audio recording application, allowing user to capture up to 2 audio clips
    navigator.device.capture.captureAudio(captureSuccess, fail, {limit: 1});
}

function captureSuccess(mediaFiles) {
    var d = new Date();
    var n = d.getTime();
    var entry = mediaFiles.fullPath;
    var file = code + "_" + n + ".m4a";
    var folder = "Test";

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
        function (fileSys) {
                fileSys.root.getDirectory(folder, {create: true, exclusive: false},
                function (directory) {
                    entry.moveTo(directory, file,
                        success, fail);
                }, fail);
        }, fail);
}


推荐答案

/ p>

Somehow i made it,

var captureSuccess = function (mediaFiles) {
    // SystemURI require string and path2 will deal it and must not use file:/(path)
    var path = mediaFiles[0].fullPath;
    var path2 = path.slice(0, 5) + "//" + path.slice(5);
    window.resolveLocalFileSystemURI(path2, successMoveTo, fail);
}

function successMoveTo(entry) {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
        function (fileSys) {
            fileSys.root.getDirectory(folder, {create: true, exclusive: false},
                function (directory) {
                    entry.moveTo(directory, file,
                        success, fail);
            }, fail);
    }, fail);
}

这篇关于在captureSuccess中移动和重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆