Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

fs renaming files

const fs = require("fs")

fs.rename("./testfile.txt", "./newtestfile.txt", (err) => {
	if (err) console.log(err)
})
Comment

Rename files in a directory with node.js

const fs = require("fs");
const path = require("path");

const folderPath = "./assets";

// read all files in the directory
let filesArr = fs.readdirSync(folderPath);

// Loop through array and rename all files 

filesArr.forEach((file, index) => {
  let fullPath = path.join(folderPath, file);
  let fileExtension = path.extname(file);
  let fileName = path.basename(file, fileExtension);

  let newFileName = fileName + index + "." + fileExtension;
try {
  fs.renameSync(fullPath, path.join(folderPath, newFileName));
} catch (error) {
  console.error(error)
}
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to use typeof in javascript 
Javascript :: remove array item from localStorage 
Javascript :: Remove duplication from array in javascript 
Javascript :: javascript iterate over divs 
Javascript :: how to handle navigation between multiple stack react native 
Javascript :: how to get a record in dynamodb nodejs 
Javascript :: remove a object name from spread operator 
Javascript :: javascript click coordinates on page 
Javascript :: change the mouse pointer javascript 
Javascript :: javascript contains substring 
Javascript :: dinosaur game hacks 
Javascript :: fetch 
Javascript :: remove node_modules folder mac 
Javascript :: Loop array backwards in JS 
Javascript :: React import image with url 
Javascript :: radiojquery 
Javascript :: jquery table row count 
Javascript :: on change field text jquery 
Javascript :: calculus of finite differences calculator 
Javascript :: package json scripts multiple commands 
Javascript :: javascript element distance from top 
Javascript :: faker.js avatar 
Javascript :: javascript get sum array values 
Javascript :: js for in 10 
Javascript :: javascript atualizar pagina 
Javascript :: angular js parse json 
Javascript :: clear interval e.close is not a function 
Javascript :: expo build ios 
Javascript :: insert new object values 
Javascript :: js set css variable 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =