Last active
November 5, 2022 01:18
-
-
Save ljahier/0fc9f7f0f4a239b7d07bed875abd34d7 to your computer and use it in GitHub Desktop.
Move all photos from google takeout into one directory.
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 { 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