fs renaming files
const fs = require("fs")
fs.rename("./testfile.txt", "./newtestfile.txt", (err) => {
if (err) console.log(err)
})
fs renaming files
const fs = require("fs")
fs.rename("./testfile.txt", "./newtestfile.txt", (err) => {
if (err) console.log(err)
})
rename a file using node.js
const { join } = require('path');
const { readdirSync, renameSync } = require('fs');
const [dir, search, replace] = process.argv.slice(2);
const match = RegExp(search, 'g');
const files = readdirSync(dir);
files
.filter(file => file.match(match))
.forEach(file => {
const filePath = join(dir, file);
const newFilePath = join(dir, file.replace(match, replace));
renameSync(filePath, newFilePath);
});
// Usage
// node rename.js path/to/directory 'string-to-search' 'string-to-replace'
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us