【问题标题】:How to check if a file (given by full path) exists? node js [duplicate]如何检查文件(由完整路径给出)是否存在?节点js [重复]
【发布时间】:2012-02-09 03:00:40
【问题描述】:

我以为我可以使用“fs”模块来做到这一点,但我找不到合适的功能。

【问题讨论】:

标签: node.js filesystems


【解决方案1】:
fs = require('fs');        
fs.exists(path, function( exists ) {        
    console.log( ( exists  ? "File is there" : "File is not there" ) );         
});

【讨论】:

  • fs = require('fs'); console.log(fs.statSync(path).isFile()); // 对或错
【解决方案2】:

请参阅documentation for the fs module,尤其是“stat”函数系列(stat、fstat、lstat、statSync、fstatSync、lstatSync)。

【讨论】:

    猜你喜欢
    • 2011-07-30
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-29
    • 2012-06-08
    • 1970-01-01
    • 2021-02-17
    相关资源
    最近更新 更多