2 ms·
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 h
by russellbeattie 4y ago
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.