index.js
function tryReaddir(filepath) {
  var ctx = { path: filepath, files: [] };
  try {
    ctx.files = fs.readdirSync(filepath);
    return ctx;
  } catch (err) {}
  try {
    ctx.path = path.dirname(filepath);
    ctx.files = fs.readdirSync(ctx.path);
    return ctx;
  } catch (err) {}
  return null;
}
function tryReaddir(filepath) {
  var ctx = { path: filepath, files: [] };
  try {
    ctx.files = fs.readdirSync(filepath);
    return ctx;
  } catch (err) {}
  try {
    ctx.path = path.dirname(filepath);
    ctx.files = fs.readdirSync(ctx.path);
    return ctx;
  } catch (err) {}
  return null;
}
function tryReaddir ( filepath ) { var ctx = { path : filepath , files : [ ] } ; try { ctx . files = fs . readdirSync ( filepath ) ; return ctx ; } catch ( err ) { } try { ctx . path = path . dirname ( filepath ) ; ctx . files = fs . readdirSync ( ctx . path ) ; return ctx ; } catch ( err ) { } return null ; }
Try to read the filepath as a directory first, then fallback to the filepath's dirname.

@param  {String} `filepath` path of the directory to read.
@return {Object} Object containing `path` and `files` if successful. Otherwise, null.
Try to read the filepath as a directory first then fallback to the filepath s dirname .