Created
October 31, 2017 13:48
-
-
Save vikrambiwal/05a1006f5428716b596402850aff7c2c to your computer and use it in GitHub Desktop.
Change or rename a file.(upper case to loer)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
if (process.argv.length <= 2) { | |
console.log('Usage: ' + __filename + ' path/to/directory'); | |
process.exit(-1); | |
} | |
var directoryPath = process.argv[2]; | |
fs.readdir(directoryPath, (err, files) => { | |
files.forEach(file => { | |
var fileName = file.replace(/(.*)\.[^.]+$/, '$1'); | |
var newFileName = | |
fileName.replace(/([A-Z]+)/g, function(match1) { | |
return '_' + match1.toLowerCase(); | |
}) + path.extname(file); | |
fs.rename(directoryPath + '/' + file, directoryPath + '/' + newFileName, function() {}); | |
console.log(directoryPath + file); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment