-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (40 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
let fs = require('fs'),
path = require('path');
let argv = require('minimist')(process.argv.slice(2));
// console.log(argv);
let config = {
raw: '.ORF',
img: '.JPG'
};
function onError(msg, err) {
console.log('Error\n%s', msg);
if (err) console.log(err);
console.log('Usage: node index.js [--path] {directory} [--del]');
process.exit();
}
let dir = argv.dir || argv._[0];
let del = argv.del || false;
if (!dir) { onError("Missing argument path");}
fs.readdir(dir, function(err, items) {
if (err) {
return onError("Path doesn't exist", err);
}
let raws = items.filter(function (item) {
return path.parse(path.join(dir, item)).ext == config.raw;
});
let orphans = raws.filter(function(item){
return items.indexOf(item.replace(config.raw, config.img)) === -1;
});
console.log('Raw files: ', raws.length);
console.log('Raw without matching JPG: ', orphans.length);
if (del) {
orphans.forEach(function(item) {
let file = path.join(dir, item);
console.log('Deleting: ', file);
fs.unlinkSync(file);
});
} else {
console.log(orphans);
console.log('info: To delete this files pass the flag --del');
}
});