Skip to content

Commit

Permalink
Modified from deleting to forcefully close files
Browse files Browse the repository at this point in the history
  • Loading branch information
Microsoft Graph DevX Tooling authored and Microsoft Graph DevX Tooling committed Jan 31, 2025
1 parent 39be60d commit 61b56b0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tools/GenerateServiceModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $TempPath = "C:\Users\CLOUDT~1\AppData\Local\Temp\"
# Check if there is any folder with autorest in the name
$AutoRestTempFolder = Get-ChildItem -Path $TempPath -Recurse -Directory | Where-Object { $_.Name -match "autorest" }

# Inside each AutoRest folder, delete all files and folders
# Go through each folder and forcefully close any open files
$AutoRestTempFolder | ForEach-Object {
$AutoRestTempFolder = $_
#Delete files and folders if they exist
Expand All @@ -56,7 +56,14 @@ $AutoRestTempFolder | ForEach-Object {
Get-ChildItem -Path $AutoRestTempFolder.FullName -Recurse | ForEach-Object {
$File = $_
if(Test-Path $File.FullName){
Remove-Item -Path $File.FullName -Recurse -Force
#Check if the file is open and close it
try{
$FileStream = [System.IO.File]::Open($File.FullName, [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None)
$FileStream.Close()
}
catch{
Write-Host "Failed to close file: $File"
}
}
}
}
Expand Down

0 comments on commit 61b56b0

Please sign in to comment.