3 回答
TA贡献1886条经验 获得超2个赞
fs.existsSync():
const fs = require("fs"); // Or `import fs from "fs";` with ESMif (fs.existsSync(path)) {
// Do something}
请注意 fs.exists()是反对的,但是 fs.existsSync()不是。(回调参数为 fs.exists()接受与其他Node.js回调不一致的参数。 fs.existsSync()不使用回调。)
fs.promises.accessasyncfs.accessexists
async
try {
await fs.promises.access("somefile");
// The check succeeded} catch (error) {
// The check failed}fs.access("somefile", error => {
if (!error) {
// The check succeeded
} else {
// The check failed
}});TA贡献1883条经验 获得超3个赞
path.exists - path.existsSync
最新情况:
path.existspath.existsSync
fs.existsfs.existsSync
TA贡献1860条经验 获得超8个赞
var fs = require('fs');function fileExists(filePath){
try
{
return fs.statSync(filePath).isFile();
}
catch (err)
{
return false;
}}- 3 回答
- 0 关注
- 2911 浏览
添加回答
举报
