News for hackers. Stuff that matters.
Re:Move all photos from Google takeout into one directory by russellbeattie on Wednesday November 02, 2022 @07:13AM (#33433959)
Thinking about this later, I realized that this script isn't even recursive. I think we've been Tom Sawyered, but I couldn't resist. I grabbed a Takeout zip I had hanging around and wrote this:

    import fs from 'fs';
    import path from 'path';

    copyMedia('Takeout');

    function copyMedia(dir) {
      fs.readdirSync(dir, {withFileTypes: true}).forEach((file) => {
        if (file.isDirectory()) {
          copyMedia(path.join(dir, file.name));
        } else {
          if (file.name.toLowerCase().endsWith('.jpg') || file.name.toLowerCase().endsWith('.mp4')) {
            fs.cpSync(path.join(dir, file.name), path.join('photos', file.name));
          }
        }
      });
    }
It uses copy instead of move, but it's fine.

There are no comments on this comment yet.