0

I want to see if the file is downloaded in the download folder? After downloading the file has to be saved in another folder.

let files = fs.readdirSync('C:\\Users\\xyz\\Downloads')
 let tmpfiles+= files.map(file =>file.split('.').pop()=='tmp'? 1:0)
 if(tmpfiles<=0){await readSave()}
 async function readSave() {
        files = fs.readdirSync('C:\\Users\\xyz\\Downloads')
        files.forEach(file => {
            
            if (file.includes('abc') && file.includes('EGF') && file.split('.').pop() == 'json')) {
                let flpath = 'C:\\Users\\xyz\\Downloads\\' + file
                let filedestPath = path.join(dataDir, folderPath, `//${file}`)
                let fldata = fs.readFileSync(flpath, 'utf-8')
                fs.writeFile(filedestPath, JSON.stringify(fldata), () => removefile(flpath))
            }

        })
    }

function removefile(flpath) {
        fs.unlink(flpath, (err) => {
            if (err) throw err
        })
    }
Satyendra
  • 14
  • 4

0 Answers0