Created
May 16, 2020 14:52
-
-
Save ckcr4lyf/55c1edaa63712ab7fdfc61f72d2d70fb to your computer and use it in GitHub Desktop.
Rename files in a given path to random hex string (removes extension)
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
#!/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