NoLog file watching

This commit is contained in:
MrFry 2019-11-02 09:37:31 +01:00
parent 7bf2e4de76
commit adef37c8ad
3 changed files with 29 additions and 6 deletions

View file

@ -6,7 +6,8 @@ module.exports = {
Beep: Beep,
WriteBackup: WriteBackup,
FileExists: FileExists,
CreatePath: CreatePath
CreatePath: CreatePath,
WatchFile: WatchFile
}
var fs = require('fs')
@ -24,6 +25,25 @@ function FileExists (path) {
return fs.existsSync(path)
}
function WatchFile (file, callback) {
if (FileExists(file)) {
fs.watchFile(file, (curr, prev) => {
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
// console.log(err)
} else {
callback(data)
}
})
})
} else {
console.log(file + ' does not eadjsalék')
setTimeout(() => {
WatchFile(file)
}, 1000)
}
}
function CreatePath (path, onlyPath) {
if (FileExists(path)) { return }