Welcome folks today in this blog post we will be extracting and parse text and tables from pdf document using pdfreader library in javascript. All the full source code of…
Category: Nodejs
Node.js Tutorial to Rename All Files in Directory With Custom Pattern Using fs Module
Sure, here’s a Node.js script that uses the fs module to rename all the files in a directory to img%d pattern:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
const fs = require('fs'); const path = require('path'); const directoryPath = './my-directory'; // change this to the path of your directory const prefix = 'img'; // change this to the prefix you want to use const extension = '.jpg'; // change this to the file extension you want to use let counter = 1; fs.readdir(directoryPath, (err, files) => { if (err) throw err; files.forEach((file) => { const oldPath = path.join(directoryPath, file); const newPath = path.join(directoryPath, prefix + counter + extension); fs.rename(oldPath, newPath, (err) => { if (err) throw err; console.log(`${oldPath} renamed to ${newPath}`); }); counter++; }); }); |
In this code, the…