-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
26 lines (19 loc) · 762 Bytes
/
Copy pathmain.js
File metadata and controls
26 lines (19 loc) · 762 Bytes
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
import fs from "fs/promises"
import fsn from "fs"
import path from "path"
const basepath = "C:\\Codingdongding\\web dev\\Projects\\clutter manager"
let files = await fs.readdir(basepath)
for (const item of files) {
console.log("running for ", item)
let ext = item.split(".")[item.split(".").length - 1]
if (ext != "js" && ext != "json" && item.split(".").length > 1) {
if (fsn.existsSync(path.join(basepath, ext))) {
// Move the file to this directory if its not a js or json file
fs.rename(path.join(basepath, item), path.join(basepath, ext, item))
}
else {
fs.mkdir(ext)
fs.rename(path.join(basepath, item), path.join(basepath, ext, item))
}
}
}