📜  fs.access 做任何事情 - 无论代码示例

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

代码示例1
import {promises as fs} from "fs";
import * as oldfs from "fs";

(async function() {
    // fs.stat has higher level abstraction
    const stat = await fs.stat(__dirname);
    console.log(stat.isDirectory());
    console.log(stat.isFile());
    console.log(stat.ctime);
    console.log(stat.size);

    try {
        // fs.access is low level API, it throws error when it doesn't match any of the flags
        // is dir exists? writable? readable?
        await fs.access(__dirname, oldfs.constants.F_OK | oldfs.constants.W_OK | oldfs.constants.R_OK);
    } catch (error) {
        console.log(`${__dirname} is not exists / writable / readable`);
    }
})();