Created
January 19, 2021 23:46
-
-
Save rjindael/64bcff61a20b68d086f0608b26fb84a3 to your computer and use it in GitHub Desktop.
Renames files in a given folder to a random string
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
const fs = require("fs") | |
const crypto = require("crypto") | |
const folder = "./Sort" | |
const files = fs.readdirSync(folder) | |
for (var i = 0; i < files.length; i++) { | |
let oldname = files[i] | |
let newname = ((crypto.randomBytes(16).toString("hex")) + "." + (oldname.substring(oldname.lastIndexOf(".") + 1))) | |
fs.rename(`${folder}/${oldname}`, `${folder}/${newname}`, (error) => { | |
if (error) console.log(`error: ${error}`) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment