In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to detect the existence of files in the fs module of node. The article is very detailed and has certain reference value. Interested friends must read it!
Detection methods: 1. Use the statement "const fs = require("fs");" to introduce the fs module;2. Use the exists() method of the fs module to detect whether the specified file exists in the file system, with the syntax "fs.exists( path,callback)."
This tutorial operating environment: Windows 7 system, nodejs version 12.19.0, DELL G3 computer.
First, you need to introduce the fs module.
const fs = require("fs");
2. Use fs module for detection
fs.exists(filePath, (exists) => { if (exists) { console.log("File already exists"); } else { console.log("File does not exist"); }});
Description:
The fs.exists() method is the fs module's built-in application programming interface, which provides an API for interacting with file systems in a tightly modeled manner around standard POSIX functions. The fs.exists() method tests whether a given path exists in the file system.
Usage:
fs.exists( path, callback )
Parameters: The method accepts two parameters described above and below:
path: Path to test for directory existence. It can be a string, buffer, etc.
callback: This is a callback function passed to the exists() method.
Return Value: It returns a Boolean value indicating that the path exists or does not exist.
The above is "node fs module how to detect the existence of files" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.