0

Here's the code:

Remove-Item -Recurse -Force -Path "data/user-data" -Include @("Backups", "Cache", "CachedData", "GPUCache", "logs")
Remove-Item -Recurse -Force -Path "data/tmp"

curl.exe -L "https://code.visualstudio.com/sha/download?build=stable&os=win32-x64-archive" -o "stable.zip"

Get-ChildItem -Exclude @("data", "update.ps1", "stable.zip") | Remove-Item -Recurse -Force

Expand-Archive -Path "stable.zip" -DestinationPath .

Remove-Item -Path "stable.zip"

Pause

As you can see, it deletes a whole bunch of files. It works fine when all of the files are not in use, but it throws a ton of exceptions when the files are in use.

Is there a way that I can pause the script while the files are still in use, but resume it as soon as all of them are free?

SunnyMonster
  • 500
  • 5
  • 14
  • Probably the easiest way is to do a [`Try`/`Catch`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_try_catch_finally) – iRon Jul 20 '21 at 09:40
  • I think this could help [Powershell: Check if a file is locked](https://stackoverflow.com/questions/24992681/powershell-check-if-a-file-is-locked) – Ivan Ignatiev Jul 20 '21 at 12:40

0 Answers0