One of the places I'm interested in Nodejs is the FS file system.
Today, we use Nodejs to implement a script that renames all the files in a folder.
The name can be customized.
' Use strict ';
var fs = require (' FS ');
var i = 0;
var $ = "$";
Setting area
var directory = './files ';
var format = ' Test ' +$;
Setting area
function Rename (filename,formation) {
Fs.readdir (Filename,function (err,data) {
Data.foreach (function (item) {
i++;
var F;
var type = Item.split ('. ');
Type = "." + type[type.length-1];
if (Formation.startswith (' $ ')) {
f = i + formation.split (' $ ') [1];
}else if (Formation.endswith (' $ ')) {
f = formation.split (' $ ') [0] + i;
}else{
var arr = formation.split (' $ ');
f = arr[0]+i+arr[1];
}
Fs.rename (directory+ '/' +item,directory+ '/' +f+type,function (ERR) {
if (err) {
throw err;
}
})
})
})
};
Rename (Directory,format);
Use Nodejs to rename all files within a folder