PowerShell Remove-Item not waiting

后端 未结 4 1642
不知归路
不知归路 2021-01-13 05:20

If have this piece of code

if(Test-Path -Path $OUT) 
{ 
    Remove-Item $OUT -Recurse 
}
New-Item -ItemType directory -Path $OUT

Sometimes

4条回答
  •  囚心锁ツ
    2021-01-13 05:55

    If you type Get-Help Remove-Item -Detailed you'll see:

    Example 4: Delete files in subfolders recursively
    PS C:\>Get-ChildItem * -Include *.csv -Recurse | Remove-Item
    
    This command deletes all of the CSV files in the current folder and all subfolder recursively.
    

    Because the Recurse parameter in Remove-Item has a known issue, the command in this example uses Get-ChildItem to get the desired files, and then uses the pipeline operator to pass them to Remove-Item .

    Do what specification recommends:

    if(Test-Path -Path $OUT) 
    { 
        Get-ChildItem $OUT -Recurse | Remove-Item
    }
    New-Item -ItemType directory -Path $OUT
    

提交回复
热议问题