Skip to content

Instantly share code, notes, and snippets.

@dylanjamesdev
Created February 13, 2022 05:09
Show Gist options
  • Save dylanjamesdev/27d26e61d3b2a05f0e7c978e6ccd60a1 to your computer and use it in GitHub Desktop.
Save dylanjamesdev/27d26e61d3b2a05f0e7c978e6ccd60a1 to your computer and use it in GitHub Desktop.
A super simple script that renames all files in a dir to random strings.
/**
* A super simple scripty to rename all files in a directory to random strings, I use this to rename hentai lmao.
* ~~uwu instructions~~
* npm i fs chalk --save
* node run [file].js
*/
const fs = require("fs"),
c = require("chalk"); // Has to 2.0.0 bc stupid esm modules
/**
* Random String Generator
*/
function randomString(length) {
var result = "";
var characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
/**
* Rename All Yaoi Images/Files on Startup
*/
async function renameYaoiImages(number) {
fs.readdir(".", (err, files) => {
files.forEach((file) => {
let newName = randomString(number);
const ext = file.split(".").pop();
fs.renameSync(`./${file}`, `./${newName}.${ext}`);
console.log(
c.yellow([`[Renamed]`]),
`${file} renamed to ${newName}.${ext}`
);
});
});
}
renameYaoiImages(15);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment