nl_tokens: check if file or path already exists and append number _ ( 1 )
pl_tokens: function checkExistsName ( filePath , isDir , callback , count ) { // callback(err, fullPath) if ( typeof callback !== 'function' ) throw new Error ( 'Wrong arguments' ) ; var pathInfo = resolve ( filePath ) , newFullPath , oldName ; count = count || 1 ; fs . exists ( pathInfo . fullPath , function ( exists ) { if ( ! exists ) callback ( null , pathInfo . fullPath ) ; else { // generate new file or dir name, and try again oldName = count > 1 ? '(' + ( count - 1 ) + ')' : '' ; if ( isDir ) { newFullPath = pathInfo . fullPath . <mask> ( new RegExp ( oldName . escape ( ) + '$' ) , '' ) + '(' + count + ')' ; } else { oldName = oldName + '.' + pathInfo . extName ; newFullPath = pathInfo . fullPath . replace ( new RegExp ( oldName . escape ( ) + '$' ) , '(' + count + ').' + pathInfo . extName ) ; } checkExistsName ( newFullPath , isDir , callback , count + 1 ) ; } } ) ; }