Skip to content

Instantly share code, notes, and snippets.

@brooksbecton
Last active January 31, 2018 15:06
Show Gist options
  • Save brooksbecton/b50bbc691416deb02e39c24b6480ef46 to your computer and use it in GitHub Desktop.
Save brooksbecton/b50bbc691416deb02e39c24b6480ef46 to your computer and use it in GitHub Desktop.
A tiny one time script for pulling small and large images out of a legacy project
(function() {
"use strict";
const imageFolderPath = "/home/yaboibrooks/Desktop/myrna_images";
const fileCount = 0;
var walk = require("walk"),
fs = require("fs"),
mkdirp = require("mkdirp"),
walker;
walker = walk.walk(imageFolderPath);
walker.on("file", function(root, fileStats, next) {
const dirTree = root.split("/");
const clothingType = dirTree[5];
const clothingId = dirTree[6];
const imageType = dirTree[7];
fs.readFile(root + "/" + fileStats.name, function(err, data) {
console.log(fileCount);
if (!err) {
if (imageType === "large" || imageType === "small") {
const path =
"./clothing/" +
clothingType +
"/" +
clothingId +
"/" +
imageType +
"/";
mkdirp(path, function() {
fs.writeFile(path + fileStats.name, data, function(err) {
if (err) {
return console.log(err);
}
});
});
}
} else {
console.error(err);
}
fileCount++;
next();
});
});
walker.on("errors", function(root, nodeStatsArray, next) {
next();
});
walker.on("end", function() {
console.log("all done");
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment