Skip to content

Instantly share code, notes, and snippets.

@ckcr4lyf
Created May 16, 2020 14:52
Show Gist options
  • Save ckcr4lyf/55c1edaa63712ab7fdfc61f72d2d70fb to your computer and use it in GitHub Desktop.
Save ckcr4lyf/55c1edaa63712ab7fdfc61f72d2d70fb to your computer and use it in GitHub Desktop.
Rename files in a given path to random hex string (removes extension)
#!/usr/bin/env node
const fs = require('fs');
const crypto = require('crypto');
if (process.argv.length < 3){
console.log(`Missing path`);
process.exit(1);
}
const path = process.argv[2];
const files = fs.readdirSync(path);
for (file of files){
const newName = crypto.randomBytes(8).toString('hex');
console.log(`Renaming ${path}\\${file} to ${newName}`);
fs.renameSync(path + '\\' + file, path + '\\' + newName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment