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
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.
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.
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));
}
}
});
}
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.
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.
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.
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.
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.
Zsh: