News for hackers. Stuff that matters.
Re:Move all photos from Google takeout into one directory by sdfhbdf on Tuesday November 01, 2022 @11:51PM (#33431246)
Hmm. You could really benefit from a couple of Linux commands that have “built in concurrency” for such use cases.

I think you could achieve the same result with just the find command:

`find ./takeout -iname “.jpg” -exec mv {} newdir`

Re:Move all photos from Google takeout into one directory by dmitrygr on Wednesday November 02, 2022 @12:52AM (#33431548)
.js ? FFS, really?

    find takeout -name ".jpg" -exec mv {} dest_dir
Re:Move all photos from Google takeout into one directory by anaganisk on Wednesday November 02, 2022 @02:28AM (#33431994)
What’s wrong with a js script if author is comfortable with it? Is it a rule that everyone must know linux commands?
Re:Move all photos from Google takeout into one directory by dmitrygr on Wednesday November 02, 2022 @02:33AM (#33432022)
> What’s wrong with a js script

Not much more than is wrong with sending a nuclear-powered aircraft carrier to kill a mosquito

> Is it a rule that everyone must know linux commands?

Unix, and yes. Every system around you is built on it or something derived from it (either literally or in design).

Re:Move all photos from Google takeout into one directory by anaganisk on Wednesday November 02, 2022 @09:14AM (#33435182)
Wrong comparison, I’ve taught enough people both UNIX and JS, and there are many of them who consider JS more easier than to grok and use than bash/unix. Not everyone wants to remember all the commands, and most of them use windows.

Also, no not every system around me requires me to learn unix, I can use my phone, microwave or even my gaming laptop(windows) without ever opening CLI. Unless Im at work or am I tinkering with my PI4s I don’t even have to touch CLI or even think about a unix command.

Re:Move all photos from Google takeout into one directory by kfrzcode on Wednesday November 02, 2022 @04:03AM (#33432550)
Yes, rules 8 and 14
Re:Move all photos from Google takeout into one directory by anaganisk on Wednesday November 02, 2022 @09:16AM (#33435228)
From Unix handbook of how to make people hate the community? C’mon author was good enough to share a script for us to use, he might be just starting in programming, or may be its for a windows use case, don’t have to be so rude like the original commenter which is what I didn’t like.
Re:Move all photos from Google takeout into one directory by kfrzcode on Wednesday November 02, 2022 @06:18PM (#33443690)
I'll refer you to rules 0 and 1
Re:Move all photos from Google takeout into one directory by jcutrell on Wednesday November 02, 2022 @08:54AM (#33434934)
There is nothing wrong with it per se, and no, you don’t have to know Linux commands to get by.

Sure, a Linux one liner might be “easier” to someone who knows Linux… but that doesn’t mean it’s “wrong.”

Re:Move all photos from Google takeout into one directory by ljahier on Wednesday November 02, 2022 @09:39AM (#33435574)
Here the author, I'm not working on windows but macos. I know, the script is not recursive but it's not the goal. The directory architecture of Google takeout > Google photos is one directory per day when there are pictures. In this directory, there are no other directory so the recursive is useless.

The goal was to make a script in quick time and I'm comfortable with nodejs that's why I chose it.

Re:Move all photos from Google takeout into one directory by justsomehnguy on Wednesday November 02, 2022 @07:31AM (#33434098)

    ls -Recurse -Filter *.jpg | mv dest_dir
Re:Move all photos from Google takeout into one directory by johntash on Thursday November 03, 2022 @12:24AM (#33446965)
Out of everything in this thread, this was the most interesting to me. I didn't know you could pipe a list of files to mv. It makes sense, I guess I just never tried it because anything I would have used it for, I would have used find or xargs instead.
Re:Move all photos from Google takeout into one directory by justsomehnguy on Thursday November 03, 2022 @09:13AM (#33450432)
This is PowerShell and it doesn't work on *nix machines because ls and mv are native binaries.

Would work on Windows, would work on *nix if change it to

    gci -Recurse -Filter *.jpg | move dest_dir
Re:Move all photos from Google takeout into one directory by russellbeattie on Wednesday November 02, 2022 @02:00AM (#33431868)
If you're using Windows, then I'd probably just use a script like this as well instead of trying to figure out whatever the equivalent of find is.

If you're not using Windows, you should probably learn to use some basic shell commands.

Also, line 19 has a bug.

Also, readdir('foo', {withFileTypes: true}) will return a list of directory entries so you can check the type without doing a stat. Also, sync versions are easier.

    fs.readdirSync(DOCS_DIR, {withFileTypes: true}).forEach((file) => {
        if(file.name.startsWith('.') || !file.isDirectory()){ return; }
        ...
    });
Re:Move all photos from Google takeout into one directory by Symbiote on Wednesday November 02, 2022 @04:51AM (#33432903)
Zsh:

  mkdir photos
  mv -v **/*.jpg **/*.mp4 photos
Bash:

  shopt -s globstar
  mkdir photos
  mv -v **/*.jpg **/*.mp4 photos
But I think I'd prefer them in a directory based on the EXIF date in the photo anyway:

Zsh:

  for i in **/*.jpg; do
    date=$(exif $i --machine-readable --tag=0x9003 | head -c 10 | tr : -)
    if [[ -n $date ]]; then
      mkdir -p $date
      mv -v $i $date
    else
      mkdir -p Unknown
      mv -v $i Unknown
      # (Check other EXIF values, e.g. DateTimeOriginal.)
    fi
  done
Re:Move all photos from Google takeout into one directory by pjc50 on Wednesday November 02, 2022 @05:32AM (#33433225)
Note: if you dump all your photos in one directory, prepare for opening that directory to be extremely slow.
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.
Re:Move all photos from Google takeout into one directory by Tempest1981 on Wednesday November 02, 2022 @11:50AM (#33437777)
Are the takeout filenames unique?

I think most cameras get to IMG_9999 and cycle back to IMG_0000

Re:Move all photos from Google takeout into one directory by ljahier on Wednesday November 02, 2022 @01:53PM (#33440115)
I only had a few thousand photos so I didn't get into this case. I modified to put in addition the name of the folder which is the date in the filename.
Re:Move all photos from Google takeout into one directory by codesink on Wednesday November 02, 2022 @12:07PM (#33438100)
I can't believe this is getting upvotes on HN, this is buggy and a simple oneliner can do it.
Re:Move all photos from Google takeout into one directory by ljahier on Wednesday November 02, 2022 @01:55PM (#33440149)
I didn't pretend to make a perfect code but just a functional code, and I share it because it can maybe help people who would encounter the same problem as me.
Re:Move all photos from Google takeout into one directory by toomuchtodo on Wednesday November 02, 2022 @02:28PM (#33440680)
Don’t feel bad! To get better at something, you must be bad at it first. Consider improvements from feedback in this thread.