Skip to content

Instantly share code, notes, and snippets.

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