Skip to content

Latest commit

 

History

History
41 lines (32 loc) · 1.05 KB

copy-paste-file.md

File metadata and controls

41 lines (32 loc) · 1.05 KB

copy paste

this is function for copy paste file in nativescript

using module

example

function execo(filename, from_dir, to_dir){
    // will create new folder if the folder not found
    if (!fileSystem.Folder.exists(to_dir)) {
        nsNode.mkdir(to_dir, null, function (err) { });
    }
    
    // location directory
    let a_path = fileSystem.path.join(from_dir, filename);
    let a_file = fileSystem.File.fromPath(a_path);
    
    // destination directory
    let b_path = fileSystem.path.join(to_dir, "");
    let b_fp = fileSystem.Folder.fromPath(b_path).getFile(filename);

    if (b_fp) {
        let binaryfile = a_file.readSync(err => {
            console.log("Error Readsync " + err.stack)
        });
        b_fp.writeSync(binaryfile, err => {
            console.log("Error " + err)
        });
    }
}

usage

execo(filename, from_dir, to_dir)