Last active
June 16, 2022 07:07
-
-
Save francescogior/61f22410029838ce99eba54547062791 to your computer and use it in GitHub Desktop.
rename-files.js
This file contains 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 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