Skip to content

Instantly share code, notes, and snippets.

@francescogior
Last active June 16, 2022 07:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francescogior/61f22410029838ce99eba54547062791 to your computer and use it in GitHub Desktop.
Save francescogior/61f22410029838ce99eba54547062791 to your computer and use it in GitHub Desktop.
rename-files.js
const fs = require("fs");
const path = require("path");
const dir = process.argv.slice(2)[0];
if (dir == null) throw new Error("No directory provided");
const files = fs
.readdirSync(dir, { withFileTypes: true })
.filter((item) => item.isFile());
files.forEach((file) => {
fs.rename(
path.resolve(dir, file.name),
path.resolve(dir, transform(file.name)),
(err) => {
if (err != null) console.log(err);
}
);
});
function transform(fileName) {
// Add transformation here
return fileName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment