Last active
July 17, 2019 15:40
-
-
Save idemax/f5d0ce0d026165f7630e9e6666ec9bf0 to your computer and use it in GitHub Desktop.
Duplicates images in the source subfolder to the root.
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
/** | |
* How to use? | |
* | |
* - Install Node.JS | |
* - Install NPM | |
* - Via terminal from here: | |
* -- Browse to the Pictures folder | |
* -- Save this script in a file called `index.js` (1st execution only) | |
* -- Execute `npm i` (1st execution only) | |
* -- Execute `node ./index.js` | |
*/ | |
const fs = require("fs-extra"); | |
const sourceFolder = `Camera Roll`; // SUBFOLDER WHO CONTAINS THE SOURCE IMAGES | |
const numImages = 20000; // HOW MANY IMAGES IT MUST TO ARCHIEVE | |
const images = fs.readdirSync(".").filter(e => { | |
return ( | |
!fs.lstatSync(e).isDirectory() && | |
e != "index.js" && | |
e != "package.json" && | |
e != "package-lock.json" | |
); | |
}); | |
images.forEach(element => { | |
console.log(`removing ${element}...`); | |
fs.unlinkSync(element); | |
}); | |
const name = new Date().valueOf().toString(32); | |
const sourceImages = fs.readdirSync(sourceFolder).filter(e => { | |
return ( | |
!fs.lstatSync(`${sourceFolder}/${e}`).isDirectory() && | |
e != "index.js" && | |
e != "package.json" && | |
e != "package-lock.json" | |
); | |
}); | |
for (let i = 0; i < numImages; i++) { | |
const sourceImage = sourceImages[i % sourceImages.length]; | |
console.log(`copying ${i}: ${sourceImage}...`); | |
fs.copyFileSync( | |
`./${sourceFolder}/${sourceImage}`, | |
`./${i}_${name}${sourceImage.substr(sourceImage.lastIndexOf("."))}` | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment