In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you nodejs how to read the contents of the folder directory, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
How does nodejs read the contents of a folder directory
First of all, the operation of files and directories in nodejs, we are divided into two types of operations on the fs file system, the first is the xxx method, and the second is the xxxSync method. Almost all fs operations fall into these two types: the first is asynchronous callbacks and the second is synchronous waits.
I. read and write to the file
1. Integrity read and write
A.fs.readFile (filename, [options], callback) / / can be used to read an entire file.
B.fs.writeFile (filename,data, [options], callback) / / data written to the file
C.fs.appendFile (filename,data, [options], callback) / / write file data
two。 Specify location to read and write
First open the file, then manipulate the file, and finally close the file.
A.fs.open (filename,flags, [mode], callback) callback (err,fd) / / Open the file
B.fs.read (fd,buffer,offset,length,position,callback) / / read the file
C.fs.write (fd,buffer,offset,length,position,callback) / / write to a file
D. fs.fsync (fd,callback) / / this function is called when the above read,write asynchronous operation is completely completed, and the close operation is finally performed.
E. fs.close (fd) / / close the file
Create and read directories
1. Fs.mkdir (path,callback); / / create a directory
2. Fs.readdir (path,callback); / / read the directory, where files in callback is all the files in the current directory
3. Fs.stat (path,callback); / / View directory and file information
4. Fs.lstat (path,callback); / / View directories and files as well as soft chain information. If you want to see soft chain, you must see this.
5. Fs.exists (path,callback); / / check to see if this directory or file exists.
Third, other operations on the directory
1.fs.realpath (path, [cache], cakkback); / / get the absolute path of the current directory or file
2.fs.utimes (path,atime,utime,callback); / / modify file access and modification time
3. Fs.chmod (path,mode,callback); / / permissions to modify files
4.fs.rename (oldPath,newPath,callback); / / modify and move the file from oldPath- > newPath
5.fs.link (srcpath,dstpath,callback); / / create a hard link (only in this coupon) fs.unlink () delete the hard link
6.fs.symlink (srcpath,stpaht,callback); / / create a soft link (any coupon) fs.readlink (path,callback) to read all the information of the soft link.
7.fs.truncate (filename,len,callback); / / truncate the file, leaving part of the file and the rest
8. Fs.rmdir (path,callback); / / Delete directory
The above is all the contents of the article "how to read the contents of a folder directory by nodejs". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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.