Created
May 2, 2021 20:24
-
-
Save zacjones93/79b99c58097a6412299970e3a4fd9f00 to your computer and use it in GitHub Desktop.
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
// 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