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
Introduction to Vue The current era of big front-...
Preface The need for real-time database backup is...
In this article, we sorted out the startup proces...
Main library binlog: # at 2420 #170809 17:16:20 s...
This article example shares the specific code of ...
Table of contents 1. Basic use of css(): 1.1 Get ...
Since I found that the push image always timed ou...
First execute the command: [root@mini61 setuptool...
Sometimes in a project, due to some irreversible ...
After I set up the PHP development environment on...
The computer system is: win7 This article is main...
Scenario: When starting tomcat in docker (version...
The following introduces the commonly used head s...
By default, PHP on CentOS 7 runs as apache or nob...
Install boost There are many ways to call C/C++ f...