Created
July 17, 2016 13:35
-
-
Save Grayda/6c7fd758386d98f68498d1d7931120d1 to your computer and use it in GitHub Desktop.
Move screenshots to folder based on size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run `npm install --save image-size mv` to install mv (for easily moving files) and image-size (for determining image dimensions) | |
var fs = require("fs") | |
var mv = require("mv") | |
var sizeOf = require('image-size'); | |
var dest = 'C:\\Users\\David\\Downloads' // The location of your downloads folder in Firefox. | |
// Watch the folder and report when an event has happened | |
fs.watch(dest, (event, filename) => { | |
// Try block because I'm lazy. This did exactly what I needed. | |
try { | |
// The filename and the type of event it is (change, rename etc.) | |
console.dir("Found " + filename + ". Event is " + event) | |
// Get the dimensions of the file that just changed | |
var dimensions = sizeOf(dest + "\\" + filename); | |
// For switch, and possibly for our filename if we wanted | |
dim = dimensions.width + "x" + dimensions.height | |
// Go through and find out what the size is | |
switch (dim) { | |
case "640x920": | |
// Move the file out of the downloads folder and into a sub-folder called 3.5. Don't make the dir if it exists, and ignore all errors | |
mv(dest + "\\" + filename, dest + "\\3.5\\" + filename, {mkdirp: false}, function(err) { }) | |
break; | |
case "640x1096": | |
mv(dest + "\\" + filename, dest + "\\4\\" + filename, {mkdirp: false}, function(err) { }) | |
break; | |
case "750x1334": | |
mv(dest + "\\" + filename, dest + "\\4.7\\" + filename, {mkdirp: false}, function(err) { }) | |
break; | |
case "1242x2208": | |
mv(dest + "\\" + filename, dest + "\\5.5\\" + filename, {mkdirp: false}, function(err) { }) | |
break; | |
case "1536x2008": | |
mv(dest + "\\" + filename, dest + "\\iPad\\" + filename, {mkdirp: false}, function(err) { }) | |
break; | |
case "2048x2732": | |
mv(dest + "\\" + filename, dest + "\\iPad Pro\\" + filename, {mkdirp: false}, function(err) { }) | |
break; | |
} | |
} catch(ex) { | |
// We don't care about errors. lulz lazy programming | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment