Duplicate remover: removing empty directories

This commit is contained in:
mrfry 2021-03-29 18:37:29 +02:00
parent 43b8d939c1
commit a2bde65425

View file

@ -125,7 +125,7 @@ function removePossibleAnswersDuplicates(path) {
} }
const dataB = utils.ReadJSON(currPath2) const dataB = utils.ReadJSON(currPath2)
dataB.questions.forEach((q2) => { dataB.questions.some((q2) => {
const percent = compareQuestionObj( const percent = compareQuestionObj(
createQuestion(q1), createQuestion(q1),
'', '',
@ -136,6 +136,7 @@ function removePossibleAnswersDuplicates(path) {
utils.deleteFile(currPath2) utils.deleteFile(currPath2)
count-- count--
delets++ delets++
return true
} }
}) })
}) })
@ -143,7 +144,27 @@ function removePossibleAnswersDuplicates(path) {
printProgressBar(currIndex, count) printProgressBar(currIndex, count)
}) })
log(`Deleted ${C('green')}${delets}${C()} files`)
log(`${C('green')}Deleting empty directories ...${C()}`)
const dirs = fs.readdirSync(path)
count = dirs.length
currIndex = 0
let deletedDirCount = 0
dirs.forEach((dir) => {
currIndex++
const currDirContent = fs.readdirSync(path + '/' + dir)
if (currDirContent.length === 0) {
fs.rmdirSync(path + '/' + dir)
deletedDirCount++
}
printProgressBar(currIndex, count)
})
log(
`Deleted ${C('green')}${delets}${C()} files, and ${C(
'green'
)}${deletedDirCount}${C()} directories`
)
} }
function clearPossibleAnswers(path, db) { function clearPossibleAnswers(path, db) {