Skip to content

Instantly share code, notes, and snippets.

@zacjones93
Created May 2, 2021 20:24
Show Gist options
  • Save zacjones93/79b99c58097a6412299970e3a4fd9f00 to your computer and use it in GitHub Desktop.
Save zacjones93/79b99c58097a6412299970e3a4fd9f00 to your computer and use it in GitHub Desktop.
// Author: Zac Jones
// Twitter: @zacjones93
// Shortcut: opt p
// requires fs
const fs = await npm("fs");
const plantName = await arg("Enter a plant name:");
const potSize = await arg("Enter pot size: ");
const shotType = await arg("Is this product or detail?", ["product", "detail"]);
const photos = await drop("Drop your images");
let renamePhotoFile = (path, plantName) => {
let tempPath = path.split("/");
tempPath.pop();
tempPath.push(plantName);
let newPath = tempPath.join("/");
fs.rename(path, newPath, (err) => {
if (err) return console.log("there was an error: ", err);
console.log("Files renamed");
});
};
photos.map((plant, index) => {
if (shotType === "detail") {
renamePhotoFile(
plant.path,
`${plantName}Detail${potSize}_${index + 1}.png`
);
} else {
renamePhotoFile(plant.path, `${plantName}${potSize}_${index + 1}.png`);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment