Friday, 12 May 2017

Renaming multiple files asyncroniosly casing error in Node.js

I am trying to rename a bunch of pre-generated testing files (1000+) asynchronously in Node.js.

The code looks like the following:

const fs = require('fs')
const { each } = require('async')

each(files, file => {
  let newfile = 'new' + file
  fs.rename(file, newfile, err => {
    err ? console.log(err) : console.log('renamed')
  }
})

This leads to following error:

Uncaught Error: ENOENT: no such file or directory, lstat '8d3320e35d22772f' at fs.lstatSync (fs.js:902:18) at Object.fs.lstatSync

Can someone advice what causing such behavior?



via Systems Rebooter

No comments:

Post a Comment