-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoveFile.js
More file actions
26 lines (25 loc) · 1009 Bytes
/
Copy pathmoveFile.js
File metadata and controls
26 lines (25 loc) · 1009 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'
import chalk from 'chalk'
import path from 'path'
export default function moveFile(confidence, oldPath, newFolder, newFilename) {
if (confidence >= 90) {
const ext = path.extname(oldPath)
let finalName = newFilename
if (!finalName.toLowerCase().endsWith(ext.toLowerCase())) {
finalName += ext
} else {
finalName = path.basename(finalName, path.extname(finalName)) + ext
}
const newPath = path.join(newFolder, finalName);
fs.rename(oldPath, newPath, function (err) {
if (err) throw err
console.log('Successfully moved!')
})
fs.appendFileSync("C:\\Users\\darry\\OneDrive\\Desktop\\changes.txt",
`${oldPath} => ${newPath}\n`,
(err) => { if (err) throw err; });
console.log(chalk.green(`Saved at suggested path ${newPath}`));
} else {
console.log(chalk.red('Insufficient confidence'));
}
}