function uniqueFilename(base, filename) {
    var ext = path.extname(filename);
    filename = path.resolve(base, filename);
    filename = path.join(path.dirname(filename), path.basename(filename, ext));

    var _filename = filename+ext;

    var i = 0;
    while (fs.existsSync(filename)) {
        _filename = filename + '_' + i + ext;
        i = i + 1;
    }

    return Promise(path.relative(base, _filename));
}
// Find a filename available in a folder
Find a filename available in a folder
Find a filename available in a folder
function uniqueFilename(base, filename) {
    var ext = path.extname(filename);
    filename = path.resolve(base, filename);
    filename = path.join(path.dirname(filename), path.basename(filename, ext));
    var _filename = filename+ext;
    var i = 0;
    while (fs.existsSync(filename)) {
        _filename = filename + '_' + i + ext;
        i = i + 1;
    }
    return Promise(path.relative(base, _filename));
}
function uniqueFilename ( base , filename ) { var ext = path . extname ( filename ) ; filename = path . resolve ( base , filename ) ; filename = path . join ( path . dirname ( filename ) , path . basename ( filename , ext ) ) ; var _filename = filename + ext ; var i = 0 ; while ( fs . existsSync ( filename ) ) { _filename = filename + '_' + i + ext ; i = i + 1 ; } return Promise ( path . relative ( base , _filename ) ) ; }
Find a filename available in a folder
Find a filename available in a folder