Skip to content

Instantly share code, notes, and snippets.

@alice-em
Created September 17, 2017 00:31
Show Gist options
  • Save alice-em/b74e13c3dac07c95fe1d5d13d78a0aff to your computer and use it in GitHub Desktop.
Save alice-em/b74e13c3dac07c95fe1d5d13d78a0aff to your computer and use it in GitHub Desktop.
// comic-copier.js
const fs = require('fs')
const os = require('os')
const path = require('path')
const sander = require('sander')
const input = '/path/from/'
const output = '/path/to'
const comics = ['.cbr', '.cbz', '.cbt']
const copier = (input, output) => {
let files = fs.readdirSync(input)
for (let i = 0; i < files.length; i++) {
let file = path.join(input, files[i])
let stat = fs.statSync(file)
if (stat.isDirectory()) {
copier(file, output)
} else if (stat.isFile() && comics.indexOf(path.extname(file)) > -1) {
console.log(`[${i}/${files.length}]Copying File: ${path.join(output, files[i])}`)
sander.copyFileSync(file).to(path.join(output, files[i]))
}
}
}
copier(input, output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment