NodeJS copies the files: Generally, the copy operation of small files uses the stream pipeline transport operation. First you need to load the imported file: var fs = require('fs'); 1. Create folders synchronously fs.mkdirSync(yourfileDirPath); Create folder asynchronously fs.mkdir(yourfileDirPath); 2. Determine whether the folder exists - Synchronize fs.existsSync(dirpath); asynchronous fs.exists(dirpath); Using the above related operations, we can directly write a method to determine the creation of a folder. function mkdir(dirpath,dirname) { //Judge whether the second parameter is normal to avoid passing in wrong parameters when calling if (dirname !== path.dirname(dirpath)) { mkdir(dirpath); return; } if (fs.existsSync(dirname)) { fs.mkdirSync(dirpath) } else { mkdir(dirname, path.dirname(dirname)); fs.mkdirSync(dirpath); } } Pay attention to synchronous and asynchronous creation, reading and other issues, otherwise the folder will not exist when copied. It is recommended to use synchronous creation Sync method, which is generally in the form of fs.xxxSync. Summarize This is the end of this article about copying node.js files, creating folders and other related operations. For more related node.js file copying and folder creation content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL initialization password operation under Mac
>>: MySQL 5.7.17 installation and configuration method graphic tutorial under win7
In our daily work, we often come into contact wit...
Table of contents docker system df docker system ...
A brief introduction to protobuf Protobuf is Goog...
1. Back button Use history.back() to create a bro...
Table of contents vue2.x vue3.x tiny-emitter plug...
The react version when writing this article is 16...
Table of contents Docker image download Start mys...
Table of contents 1. Background 2. Local custom i...
1. Why set maxPostSize? The tomcat container has ...
Today I suddenly thought that the styles of check ...
I believe some people have seen this picture of c...
MySql uses joined table queries, which may be dif...
This article introduces common problems of Xshell...
Download and install. First check whether there i...
Preface Previously, static IPs assigned using pip...