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 :: jquery button remove disabled attribute 
Javascript :: javascript remove leading zeros from string 
Javascript :: 1 line unique id 
Javascript :: node console log without newline 
Javascript :: get attribute of selected option jquery 
Javascript :: use json file for data jquery 
Javascript :: jquery check if element has css display none 
Javascript :: git ignore .env files not working 
Javascript :: set time out js 
Javascript :: express post body undefined 
Javascript :: regex yyyy-mm-dd 
Javascript :: js show span for 5 seconds 
Javascript :: 50 50 chance javascript 
Javascript :: set value javascript by id 
Javascript :: running shell commands javascript 
Javascript :: Could not resolve dependency: npm ERR! peer react@"17.0.1" from react-dom@17.0.1 
Javascript :: javascript scroll to element 
Javascript :: react native flatlist get visible items 
Javascript :: ajax request header laravel 
Javascript :: in array jquery 
Javascript :: js redirect to relative url 
Javascript :: execute javascript function when page loads 
Javascript :: wait for element javascript 
Javascript :: js is function 
Javascript :: gdscript yield timer 
Javascript :: req.body is undefined 
Javascript :: react js usehistory push and pass props 
Javascript :: domain regex 
Javascript :: Could not find com.yqritc:android-scalablevideoview:1.0.4 react native video 
Javascript :: how to remove https link from javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =