Last active
October 31, 2017 07:16
-
-
Save XANOZOID/5ba225c8019d602c8043d7bdb689f4c5 to your computer and use it in GitHub Desktop.
Fixes incorrect, specified, file extensions in a specified directory
This file contains hidden or 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
/* usage: `node extension_fixer.js ext-name (/)sub-folder */ | |
/* sub folder is optional. */ | |
/** | |
* Goes over all files in the current directory | |
* - checks if they have an incorrect extension name | |
* - prints out the conflict | |
* - changes their file name. | |
* --- Limitations: | |
* Only fixes letter-case conflicts. | |
*/ | |
const fs = require('fs'); | |
const path = require('path'); | |
var dext = process.argv[2]; | |
var dir = __dirname + ( process.argv[3] || "" ); | |
fs.readdir(dir, (err, files) => { | |
files.forEach(file => { | |
var res = file.split('.'); | |
if( res[1] !== dext && res[1].toLowerCase() === dext ){ | |
var fix = res[0] + '.' + dext; | |
console.log("ext-error: \"", file, "\""); | |
console.log("\tfixing to: \"", fix , "\"") | |
fs.rename( file, fix, function(err) { | |
if ( err ) console.log('RENAME ERROR: ' + err); | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment