Languages
[Edit]
EN

Node.js - rename multiple files

0 points
Created by:
lena
714

In this article, we would like to show you how to rename multiple files in Node.js.

Quick solution:

Note:

If the newPath already exists, it will be overwritten.

 

Practical example

Edit

Let's say we have the following project structure:

To rename usr.js files we will use:

  • for...of statement to iterate the Users/ directory,
  • fs.readdirSync() to get the file names from Users/ directory,
  • fs.rename() to actually rename the usr.js files.

Result:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
πŸš€
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

β€οΈπŸ’» πŸ™‚

Join