'VS Code - Error: EPERM: operation not permitted

I have been experiencing A LOT of permission issues when using VS code with Windows 10.

  1. When trying to move a folder:
    • Error: EPERM: operation not permitted, rename 'path a' -> 'path b'
  2. When deleting a folder:
    • It fails silently, the folder is removed from the solution explorer but it persists on disk.

It doesn't work with or without admin rights.

I went to the folder containing all my repos, set the ownership to me, applied full control to all authenticated users, and it still doesn't work.

enter image description here

Any idea ?

EDIT: It does work sometimes, that's what make it very strange



Solution 1:[1]

I encountered the error message when renaming or moving files in VS Code. I then noticed that it was the same in Windows Explorer.

I develop in Angular using Angular-CLI and I execute the command ng build --watch in a cmd.

When I stopped the watch command, that solved the issue and I was able to rename and move files in VS Code without any problem.

So I think there are some processes that hold your files. I hope this can help.

Solution 2:[2]

I had this issue as well. The cause in my case appeared to be the "Angular Language Service" extension.

I killed that in the extensions pane and was able to rename the file immediately.

Unfortunately, the problem still persists when Angular Language Server is enabled.

Solution 3:[3]

I faced the same issue while doing a react project. At first, I thought I need to give admin rights but that also didn't work. Later I found that My project was hosted on my localHost. So, If your project is running we can't change the folder structure. You need to quit the server before updating the folder structure.

Solution: Quit the Localhost Server and try again(For React and Angular Users). You can also try restarting the VScode.

Solution 4:[4]

If you use the Jest VSCode extension and a test file is located in the folder you're trying to rename, it might not work without disabling the Jest runner.

Solution 5:[5]

Just close the vscode and do any file operations in file explorer. I still rename my files using this way, perhaps this is an unsolved bug.

Solution 6:[6]

I encountered Error: EPERM: operation not permitted, rename while having the live server of the Live Server extension running. After stopping the live server the renaming operation was possible again.

Solution 7:[7]

The solution that worked for me was to open Vscode as admin.

Solution 8:[8]

If you're developing Firebase app and have its Firebase Emulators previously running, this might happen because when you press Ctrl+C, their emulators may not completely shutdown. No one mention which background process can be ended in the windows Task Manager either.

In short, when this problem happen, it has to be some kind of CLI or Extension that is holding up the resources.

SOLUTION: Restart PC and try renaming or removing your folder again, it should work.

Solution 9:[9]

As silly as it sounds, this error also happens when a file's 'read-only' flag is set for any reason; in my case it was copying the entire VSCode folder from a read-only host-share to a VM. It doesn't matter whether you have full admin rights or not, if file is read-only VSCode cannot change it. As for open files, you can use SysInternals' Process Explorer tool to find out which process has an open handle to a particular path or file.

Solution 10:[10]

In my case it was a nested folder. Manually creating the top folder and moving it's contents was allowed... (imports were still automatically updated)

Solution 11:[11]

Just to add to this wall of answers, this is pretty clearly a very context dependent problem, I initially assumed this was something to do with vscode or my windows permissions but actually it was a problem with my deletion script.

Initially my script was something like this:

  fs.readdir("./content/products", (err, files) => {
    if (err) console.log(err);
    else {
      files.forEach((file) => {
        console.log(`Deleting: ${file}`);
        fs.unlink(`content/products//${file}`, (err) => {
          if (err) throw err;
        });
      });
    }
  });

And this worked for most of my time with this project.... until I decided to make subfolders in the products directory at which point node attempted to unlink the directories and this error was raised. Couldn't figure out why this was happening even after rebooting my PC :/

I changed my deletion script to

 try {
    await fs.emptyDir("content/products");
  } catch (err) {
    console.error(err);
  }

And it works now :)

Solution 12:[12]

I had the same issue in VSCode with Angular. I was trying to rename a component folder.

The solution for me was to remove the compiled Angular (.js) files from folder_to_rename/dist/ folder. After that, I could rename the parent folder without issues.

Solution 13:[13]

I also got this error while developing in React Native, it was because the app was running and constantly listening for the changes in the code. Terminating the Metro worked.

Solution 14:[14]

"C:\Users{username}" If you don't see the .vscode folder under this path, this may be your problem. Making the .vscode folder visible will solve your problem. It worked for me. If you don't know how to make it visible follow the below steps. see hidden files Make the folder visible from this link and then right click on the folder, select properties from the popup menu, check the box next to hidden in the popup window and then click ok. Your problem should be resolved.

Solution 15:[15]

In my case, I tried moving React packages into a new folder I created in VS Code but the error message persisted.

I solved it by closing the google-chrome browser where the app was running.

I tried again and it worked :)