Rename-Item: Access to the path is denied (Flutter upgrade)

Viewed 4319

My previous Flutter version is installed in C:\src\flutter.

When I try to upgrade Flutter, I get this error:

Downloading Dart SDK from Flutter engine
Rename-Item : Access to the path 'C:\src\flutter\bin\cache\dart-sdk' is denied.
At C:\src\flutter\bin\internal\update_dart_sdk.ps1:51 char:5
+     Rename-Item $dartSdkPath "$oldDartSdkPrefix$oldDartSdkSuffix"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (C:\src\flutter\bin\cache\dart-sdk:String) [Rename-Item], IOException
    + FullyQualifiedErrorId : RenameItemIOError,Microsoft.PowerShell.Commands.RenameItemCommand

I think something is wrong with my drive permission on Windows, but I don't know how to solve it.

8 Answers

The problem is that Windows is unable to rename the dart-sdk folder. For me it was because the folder was locked by some processes. To solve such problem:

  1. Go to Resource Monitor (on windows 10 : Task Manager > Performance > Open Resource Monitor)
  2. CPU > Associated Handles
  3. Search for dart-sdk
  4. End processes locking the folder

Referring to @navid's reply:

YES! That worked for me. Slightly different path (win 10):

*open 'task manager'/ 'processes'*

and then just look for 'dart.exe' (couldn't install dart) or whatever is bothering you and re-run the process you wanted to work.

First try the solution on the image. Then try running your IDE as an administrator. If none of these solutions work, install your flutter sdk in a different directory and change the PATH variable.

enter image description here

I would suggest to just close whatever IDE specifically either vs code or android studio running in the background and then run the "flutter upgrade" command again and it should work. Basically, what I think was happening in the backend was that flutter upgrade wasn't able to do the renaming and all because dart.exe was engaged in process by some other program (IDE in our case I suppose).

Close your IDE, open your flutter folder then folder bin, and run flutter.bin flutter.bin

The result must be like this:

cmd.exe result

If you do not close your IDE, you will see the same error in the cmd.exe window.

Close applications that have an open directory C:\src\flutter\bin\cache\dart-sdk It is possible that IE/FileManager open has this location.

I had this same problem what I did was:

  1. open the PowerShell as administrator
  2. Run flutter upgrade
  3. ready.

I had this same problem what I did was:

  1. close the IDE
  2. Open the Cmd(Command Prompt) or PowerShell
  3. Go to flutter path => C:\flutter
  4. Run the git clean -xffd command
  5. Then call the git pull command
  6. Run flutter upgrade
Related