-
-
Save stvhanna/45c58585c64b5aacad400a1b94aad725 to your computer and use it in GitHub Desktop.
Move all photos from google takeout into one directory.
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
const { mkdir, readdir, rename, stat } = require('fs/promises'); | |
async function main() { | |
try { | |
await mkdir('./photos') | |
console.debug('Photo directory successfully created'); | |
} catch (err) { | |
console.debug('Photo directory already exist'); | |
} | |
const dirs = await readdir('./'); | |
dirs.forEach(async (dir) => { | |
if ((await stat(dir)).isDirectory()) { | |
const files = await readdir(dir); | |
console.log('Files from dir: ', dir); | |
files.forEach(async (file) => { | |
if (file.endsWith('.jpg') | file.endsWith('.mp4')) { | |
console.log(file); | |
await rename(`${dir}/${file}`, `./photos/${dir}_${file}`); | |
} | |
}) | |
} | |
}) | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment