Node.js检查路径是文件还是目录 [英] Node.js check if path is file or directory
本文介绍了Node.js检查路径是文件还是目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要做的就是能够知道给定的路径是否是一个文件或一个目录(文件夹)。
解决方案
fs.lstatSync(path_string).isDirectory()
应该告诉你。从文档:
从fs.stat()和fs.lstat()返回的对象属于这种类型。
stats .isFile()
stats.isDirectory()
stats.isBlockDevice()
stats.isCharacterDevice()
stats.isSymbolicLink()(仅适用于fs.lstat())
stats.isFIFO()
stats.isSocket()
I can't seem to get any search results that explain how to do this.
All I want to do is be able to know if a given path is a file or a directory (folder).
解决方案
fs.lstatSync(path_string).isDirectory()
should tell you. From the docs:
Objects returned from fs.stat() and fs.lstat() are of this type.
stats.isFile() stats.isDirectory() stats.isBlockDevice() stats.isCharacterDevice() stats.isSymbolicLink() (only valid with fs.lstat()) stats.isFIFO() stats.isSocket()
这篇关于Node.js检查路径是文件还是目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文