I was trying to copy my files to a new destination using fs and then rename them to like 1.png , 1.txt and so on but i always get an error here is my code :
const fs = require('fs');
const path = require('path')
const dir = 'files/newFiles'
const fileNames = fs.readdirSync('files')
for(let i = 0 ; i < fileNames.length ; i++) {
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
if(!fs.existsSync(dir+'/image')) fs.mkdirSync(dir+'/image');
if(!fs.existsSync(dir+'/txt')) fs.mkdirSync(dir+'/txt');
}
const ext = path.extname(fileNames[i])
if(ext === '.png') return fs.copyFileSync(fileNames[i], dir+'/image/'+i+ext)
if(ext === '.txt') return fs.copyFileSync(fileNames[i], dir+'/txt/'+i+ext)
}
here is the error message :
Error: ENOENT: no such file or directory, copyfile 'file1.png' -> 'files/newFiles/image/'
Via Active questions tagged javascript - Stack Overflow https://ift.tt/WKON2ns
Comments
Post a Comment