Skip to content

Instantly share code, notes, and snippets.

@IgorHalfeld
Last active September 7, 2016 05:36
Show Gist options
  • Save IgorHalfeld/b93125c81e39149771fabc725ef5181e to your computer and use it in GitHub Desktop.
Save IgorHalfeld/b93125c81e39149771fabc725ef5181e to your computer and use it in GitHub Desktop.
'use strict'
const fs = require('fs')
let c = 0
// Folder to inspect
// =================
const PATH = 'artes'
// File that will be deleted
// =========================
const FILE = /_3\.png/
// Inspect folder
// =============
const inspect = f => fs.readdir(`${__dirname}/${f}`, (err, result) => err ? new TypeError(err) : verify(result, f))
// Verify file
// ===========
function verify (arr, f) {
if (c == arr.length) {
arr.forEach(file => {
if (!FILE.test(file)) {
fs.unlink(`${__dirname}/${f}/${file}`, err => {
console.log('Deleted:', file)
})
}
})
}
arr.forEach(file => {
inspect(`artes/${file}/screenshot`)
})
c++
}
inspect(PATH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment