-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_util.js
More file actions
48 lines (41 loc) · 1.17 KB
/
Copy pathapp_util.js
File metadata and controls
48 lines (41 loc) · 1.17 KB
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
const fs = require('fs');
const path = require('path');
module.exports.setup = function(dir) {
var i = 65;
var j = 91;
for(k = i; k < j; k++) {
var letter = String.fromCharCode(k);
if(!fs.existsSync(dir + '/' + letter)) {
fs.mkdirSync(dir + '/' + letter);
}
}
}
module.exports.uploadVideos = function(dir) {
fs.readdir(dir + '/upload', function(err, files) {
if(err) {
console.log('Could not re-upload files to directories');
}
files.forEach((file, index) => {
var filename = path.basename(file);
console.log(filename);
var from = dir + '/upload';
var to = dir + '/video/' + filename.charAt(0).toUpperCase();
console.log(to);
var beginningChar = filename.charAt(0);
if(!isNaN(beginningChar)) {
to = dir + '/video/#';
}
var fromPath = path.join(from, file);
console.log(fromPath);
var toPath = path.join(to, file);
console.log(toPath);
fs.rename(fromPath, toPath, (error) => {
if(error) {
console.log(error);
} else {
console.log("Uploaded '%s' to '%s'.", fromPath, toPath);
}
});
});
});
}