#!/usr/bin/env node 'use strict'; const fs = require('fs'); const mv = require('mv'); const raw = './raw'; const video = './video-raw'; // photo raw file extensions const rawPhoto = ['CR3', 'CR2', 'CR1', 'xmp', 'DNG', 'CRW', 'SR2', 'SRF', 'ARW', 'TIFF', 'ORF', 'NEF', 'NRW', 'PEF', 'RW2']; // video raw file extensions const rawVideo = ['MP4', 'MOV', 'SRT', 'LRF']; fs.readdir('./', (err, files) => { // find each file in the directory files.forEach(file => { //console.log(file); const fileType = file.split('.')[1]; // if CR2 file type move to raw directory if(rawPhoto.includes(fileType)) { // if raw directory doesn't exist create one if (!fs.existsSync(raw)){ fs.mkdirSync(raw); } // move any CR2 file to raw directory mv(file, `raw/${file}`, function(err) { if(err) { console.log(err); } }); }else if(rawVideo.includes(fileType)) { // if video directory doesn't exist create one if (!fs.existsSync(video)){ fs.mkdirSync(video); } // move any MP4 file to video directory mv(file, `video-raw/${file}`, function(err) { if(err) { console.log(err); } }); } }); // success message console.log('Files have been organized'); })