📜  fs.access 不访问回调 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:55.077000             🧑  作者: Mango

代码示例1
const checkPermissions = file => {
  try {
    fs.accessSync(file, fs.constants.R_OK);
    console.log('can read/write');
    return true;
  } catch (err) {
    console.error('is not readable is readable________________');
    return false;
  }
};

if (checkPermissions('./some/location/file.pdf')) {
  console.log('I have permissions to the file');
} else {
  console.error('I do NOT have permissions to the file');
}