Get the App
SLTechnology News&Howtos  ›  Development  › 

How does nodejs read the contents of a folder directory

Shulou Source: shulou.com Published: 2022-06-02 05:39:05 09月30日 Update

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!

Tags: Files directories contents links folders information articles data methods not much location functions most integrity time more permissions knowledge systems industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker macOS Microsoft Shulou Tech Info NVidia