Skip to content

Instantly share code, notes, and snippets.

@samuelmaddock
Last active August 29, 2015 14:15
Show Gist options
  • Save samuelmaddock/2bcf3a7a710ed7642575 to your computer and use it in GitHub Desktop.
Save samuelmaddock/2bcf3a7a710ed7642575 to your computer and use it in GitHub Desktop.
Renames files using `#U[\w\d]{4}` names to their actual unicode character.
var fs = require('fs');
var files = fs.readdirSync('.');
var UNICODE_PATTERN = /#U([\d\w]{4})/gi;
for (var i = 0; i < files.length; i++) {
var filename = files[i];
if (!UNICODE_PATTERN.test(filename)) { continue; }
var fixedFilename = filename.replace(UNICODE_PATTERN, function (match, grp) {
var codePoint = parseInt(grp, 16);
return String.fromCharCode(codePoint);
});
console.log(filename);
console.log("=>", fixedFilename);
fs.renameSync(filename, fixedFilename);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment