Home>Article>Web Front-end> How to determine whether it is a file or a folder in node
In node, you can use the isFile() and isDirectory() methods to determine whether it is a file or a folder. The isFile() method can detect whether it is a regular file and returns "true" if it is; the isDirectory() method can detect whether it is a folder and returns "true" if it is.
The operating environment of this tutorial: windows7 system, nodejs version 12.19.0, DELL G3 computer.
node determines whether the file or folder is opened
var fs = require("fs"); //判断打开的是文件 还是 文件夹 var path = "wen.txt"; fs.stat(path,function(err,stat){ if (err) { console.error(err); throw err; } console.log(stat); console.info(path+"是一个"+stat.isFile()); console.info(path+"是一个"+stat.isDirectory()); }); console.info("打开文件成功··");
Instructions:
isFile( )
isDirectory()
nodejs tutorial! !
The above is the detailed content of How to determine whether it is a file or a folder in node. For more information, please follow other related articles on the PHP Chinese website!