Reputation: 3680
I have been experiencing A LOT of permission issues when using VS code with Windows 10.
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.
Any idea ?
EDIT: It does work sometimes, that's what make it very strange
Upvotes: 93
Views: 131142
Reputation: 2382
This seems to be a problem related to running MULTIPLE processes inside VSCode, and with this disallowing the move of folders.
I received this error while running an Angular 17 app and a NodeJS server at the same time, and trying to move one of the project folders:
I solved it in Windows 11 by using File LockSmith.
Stop all the visible task and processes you may have running:
And then execute File Locksmith in the projects root folder (in this case, named _ta-app
).
Press End Task
buttons for all child processes, except for the main VSCode editor one.
That should enable moving/renaming folders.
As you can see, it is working now.
Upvotes: 0
Reputation: 6499
With me it not replated to permission (admin/non admin). When the module was load or running, it prevent rename or move file..
Just restart VS to resolve
Upvotes: 0
Reputation: 1
The only solution that worked for me was to close VSC, make the changes I needed in Windows Explorer, and then reopen VSC
Upvotes: 0
Reputation: 572
Unfortunately none of the solutions worked for me. I ended up simply creating a new folder and moving the contents there.
Upvotes: 0
Reputation: 888
This is something I want to explain in deeper detail because I've encountered this problem many times, as have many other people here, but I decided to find out what the source of the problem is.
In short, there could be many, but as mentioned in other comments, in most cases its because some program is keeping hold of the folder you are trying to rename (The problem appears mostly with folders, because they may contain other files and folders opened by the same unknown program as well).
I decided to use a tool that shows which files and in which program are currently open. Quite expectedly, that tool turned out to be Process Explorer from Microsoft. It isn't included with Windows by default, but it does the thing very good.
Be patient - it can take a while to start it and for a while it seems that the program didn't start. Running the task manager helped to make sure that the process explorer was running and after a minute its window appeared.
Now you can use the menu item "Find -> Find Handle or DLL... (Ctrl+Shift+F)". In the popup window you should specify the name of the folder you are interested in and start the Search. When the search is over, all open handles that were found will appear in the list together with the process (application) that opened them.
Now you can either close the application, if you don't need it at the moment, or close the handles themselves.
It is probably clear how to close an application, but if it is not clear, you can simply kill the application process in the process browser. To do this, click on one of the found handles so that it appears in the process tree together with its process, and then choose "Kill Process" from the context menu.
If you do not want to close the application that opened the files (let's say it's VSCode itself), you can close only the handles of the opened files. To do this, click on one of the handles to display it in the process tree together with its process. In this case, the process you are looking for will be highlighted in the process tree and all handles opened by it will appear in the list in the lower half of the window, and the handle you are looking for will also be highlighted. Now you can choose "Close Handle" from the context menu of the handle. Do this for all handles whose path includes the folder (or file) you are looking for.
Sadly, it was non of the extensions (because all of them I have turned off and restarted VSCode), but rather VSCode itself. So, I had to close all the handles manually to let VSCode to update imports on folder rename. IMO, that seems to be the VSCode's bug.
Upvotes: 0
Reputation: 6562
My solution: run the command in GitBash
I can't get it to work inside Visual Studio Code, but it works fine i GitBah.
I tried restarting my computer too. It still fails in Visual Studio Code.
Upvotes: 0
Reputation: 663
For the vs code extension developers who are facing the same issue, use fs-extra instead of fs in your extension code.
const fse = require('fs-extra');
const sourcePath = '/path_a';
const destinationPath = '/path_b';
fse.move(src, dest, err => {
if (err) {
console.error(err);
} else {
console.log('success!')
}
});
Upvotes: 0
Reputation: 1268
I was testing SSH work and the config files triggered the same issue on Windows. What I have discovered is that the file was by default hidden. In case you untick it and allow the User to have permission to run it that solved my problem. Good luck!
Upvotes: 0
Reputation: 9
I removed all extensions I don't need including Angular extension which caused this problem for some people, but it didn't solve the issue.
Here's how I solved it: I closed my VS Code, opened my project in file explorer, and renamed my file using file explorer. It sounds weird but did the trick.
Upvotes: 0
Reputation: 41
One of the solutions that did not write above and that helped me: disable the sandbox mode. This mode was not enabled for me before, but today, faced with the problem of a permit on renaming a folder, I found that I have a sandbox mode, while in the settings the mode was marked as default.
Upvotes: 4
Reputation: 1071
I am working in a monorepo using Turbo Repo which is watching several apps and packages, I came to this very same issue. I had to stop the dev server in order to be able to rename and move files.
Upvotes: 0
Reputation: 966
If you're using Next 13 you need to turn off any running server before trying to change nested files.
Upvotes: 2
Reputation: 1904
NOTE: Make sure the extension is updated.
No need of uninstalling or disabling the extension entirely as suggested above.
Angular 15.0
Angular Language Service v15.0.2
VSCode 1.73.1
Upvotes: 0
Reputation: 1000
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 :)
Upvotes: 0
Reputation: 71
"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.
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 695
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.
Upvotes: 0
Reputation: 1519
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 :)
Upvotes: 0
Reputation: 661
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.
Upvotes: 44
Reputation: 1421
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.
Upvotes: 5
Reputation: 2941
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.
Upvotes: 4
Reputation: 253
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.
Upvotes: 20
Reputation: 31
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.
Upvotes: 3
Reputation: 353
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.
Upvotes: 4
Reputation: 581
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)
Upvotes: 8
Reputation: 1828
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.
Upvotes: 1
Reputation: 934
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.
Upvotes: 91