core/utils/helpers/path.js
function(source, destination, i, callback, excluded) {
        var isExcluded = false;
        if ( typeof(excluded) != 'undefined' && excluded != undefined) {
            var f, p = source.split('/');
            f = p[p.length-1];
            for (var r= 0; r<excluded.length; ++r) {
                if ( typeof(excluded[r]) == 'object' ) {
                    if (excluded[r].test(f)) {
                        isExcluded = true
                    }
                } else if (f === excluded[r]) {
                    isExcluded = true
                }
            }
        }


        if (!isExcluded) {
            fs.lstat(destination, function(err, stats) {

                //Means that nothing exists. Needs create.
                if (err) {
                    startCopy(source, destination, i, function(err, i) {
                        //TODO - log error.
                        callback(err, source, i)
                    })
                } else {

                    if ( stats.isDirectory() ) {
                        var str;
                        var path = '/'+ (str = source.split(/\//g))[str.length-1];
                        destination += path
                    }

                    fs.exists(destination, function(replaceFlag) {
                        if (replaceFlag) {
                            fs.unlink(destination, function(err) {
                                //TODO - log error.
                                startCopy(source, destination, i, function(err, i) {

                                    callback(err, source, i)
                                })
                            })
                        } else {
                            startCopy(source, destination, i, function(err, i) {
                                //TODO - log error.
                                callback(err, source, i)
                            })
                        }
                    })
                }//EO if (err)
            })
        } else {
            callback(false, source, i)
        }

        var startCopy = function(source, destination, i, callback) {

            copyFile(source, destination, i, function(err, i) {
                if (err) {
                    console.error(err.stack)
                }
                callback(err, i)
            })
        }
    }
function(source, destination, i, callback, excluded) {
        var isExcluded = false;
        if ( typeof(excluded) != 'undefined' && excluded != undefined) {
            var f, p = source.split('/');
            f = p[p.length-1];
            for (var r= 0; r<excluded.length; ++r) {
                if ( typeof(excluded[r]) == 'object' ) {
                    if (excluded[r].test(f)) {
                        isExcluded = true
                    }
                } else if (f === excluded[r]) {
                    isExcluded = true
                }
            }
        }


        if (!isExcluded) {
            fs.lstat(destination, function(err, stats) {

                //Means that nothing exists. Needs create.
                if (err) {
                    startCopy(source, destination, i, function(err, i) {
                        //TODO - log error.
                        callback(err, source, i)
                    })
                } else {

                    if ( stats.isDirectory() ) {
                        var str;
                        var path = '/'+ (str = source.split(/\//g))[str.length-1];
                        destination += path
                    }

                    fs.exists(destination, function(replaceFlag) {
                        if (replaceFlag) {
                            fs.unlink(destination, function(err) {
                                //TODO - log error.
                                startCopy(source, destination, i, function(err, i) {

                                    callback(err, source, i)
                                })
                            })
                        } else {
                            startCopy(source, destination, i, function(err, i) {
                                //TODO - log error.
                                callback(err, source, i)
                            })
                        }
                    })
                }//EO if (err)
            })
        } else {
            callback(false, source, i)
        }

        var startCopy = function(source, destination, i, callback) {

            copyFile(source, destination, i, function(err, i) {
                if (err) {
                    console.error(err.stack)
                }
                callback(err, i)
            })
        }
    }
function ( source , destination , i , callback , excluded ) { var isExcluded = false ; if ( typeof ( excluded ) != 'undefined' && excluded != undefined ) { var f , p = source . split ( '/' ) ; f = p [ p . length - 1 ] ; for ( var r = 0 ; r < excluded . length ; ++ r ) { if ( typeof ( excluded [ r ] ) == 'object' ) { if ( excluded [ r ] . test ( f ) ) { isExcluded = true } } else if ( f === excluded [ r ] ) { isExcluded = true } } } if ( ! isExcluded ) { fs . lstat ( destination , function ( err , stats ) { //Means that nothing exists. Needs create. if ( err ) { startCopy ( source , destination , i , function ( err , i ) { //TODO - log error. callback ( err , source , i ) } ) } else { if ( stats . isDirectory ( ) ) { var str ; var path = '/' + ( str = source . split ( / \/ / g ) ) [ str . length - 1 ] ; destination += path } fs . exists ( destination , function ( replaceFlag ) { if ( replaceFlag ) { fs . unlink ( destination , function ( err ) { //TODO - log error. startCopy ( source , destination , i , function ( err , i ) { callback ( err , source , i ) } ) } ) } else { startCopy ( source , destination , i , function ( err , i ) { //TODO - log error. callback ( err , source , i ) } ) } } ) } //EO if (err) } ) } else { callback ( false , source , i ) } var startCopy = function ( source , destination , i , callback ) { copyFile ( source , destination , i , function ( err , i ) { if ( err ) { console . error ( err . stack ) } callback ( err , i ) } ) } }
Copy file to  file

@param {string} source
@param {string} destination
@param {number} [i]
@param {number} [fileCount]

@callback callback
@param {bool|string} err
Copy file to file