What settings need to be changed not to get "operation not permitted" error messages in Node

I have been developing a Node project and got to the pont when I wanted to copy images between folders with fs.copyImage() only to get “operation not permitted” error messages in gitbash. I can read and write existing HTML, css, scss files with no problem at all, but it would be also a very important part of the project to be able to copy - delete - and rename image files. I am working on a laptop running Windows 10 Pro. Does anyone have an idea what could be the reason for this restriction?

Without seeing the code or what you’ve done, it’s going to be difficult to diagnose, but the general statement is going to be that whatever directory you’re trying to copy an image to, the program doesnt have permission to write (or read? is copyImage a write operation or just a read into memory operation?) to.

Thanks for your reply!

  fs.readdir(baseFolder, (err, items) => {
    items.forEach((item) => {
      let stats = fs.statSync(`${baseFolder}/${item}`);
      if(stats.isFile(baseFolder + '/' + item) && pics.includes(item)){
        console.log('will save this image: ' + item + '\nto this path: ' + baseFolder + '/' + path + '/pics');
        fs.copyFile(`${baseFolder}/${item}`, `${baseFolder}/${path}/pics`, (err) =>{
          if(err){ console.log(err)}

where **path** points to the target folder, **pics** is an array of image file names and **baseFolder** is the current working folder for the code.

does ${baseFolder}/${path}/pics exist as a folder?

Yes, sure.

What does your console.log line say to you when it runs, and does your node user have permission to write to the directory specified?

I’ll come back to this in a few days when I have reinstalled windows after I set different permissions for programs and folders yesterday only to create a chaos.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.