-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (40 loc) · 1.5 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
51
52
// Require FS and PATH and CHALK
var fs = require('fs');
var path = require('path');
var chalk = require('chalk');
module.exports = {
sortFolder: function (Folder) {
// Set Intervall
var interval = setInterval(function () {
sortFolder(Folder)
}, 1000);
async function sortFolder(Folder) {
Folder.forEach(folder => {
fs.readdirSync(folder).forEach(file => {
var isFolder = fs.statSync(path.join(folder, file)).isDirectory();
if (isFolder) return;
let extennsion = path.extname(file);
let newFolder = folder + '/' + extennsion
let oldPath = folder + '/' + file
let newPath = newFolder + '/' + file
createFolder(newFolder)
moveFile(oldPath, newPath)
});
});
}
async function createFolder(folder) {
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder, { recursive: true });
}
}
async function moveFile(oldPath, newPath) {
fs.rename(oldPath, newPath, function (err) {
if (err) {
chalk.cyan(`[Sort Folder]`) + chalk.red(` ${err} `)
} else {
console.log(chalk.cyan(`[Sort Folder]`) + chalk.yellow(` ${oldPath} `) + chalk.cyan(` moved to `) + chalk.yellow(newPath));
}
});
}
}
}