Cannot remove item. The directory is not empty

后端 未结 3 943
心在旅途
心在旅途 2021-02-01 13:13

I am trying to delete a folder with subfolders/files.

Remove-Item -Force -Recurse -Path $directoryPath

I am getting the error Cannot remo

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 13:52

    You could try the following:

    Remove-Item -Force -Recurse -Path "$directoryPath\*"
    

    Note when using the -Recurse parameter with -Include in Remove-Item, it can be unreliable. So it's best to recurse the files first with Get-ChildItem and then pipe into Remove-Item. This may also help if you deleting large folder structures.

    Get-ChildItem $directoryPath -Recurse | Remove-Item -Force   
    

提交回复
热议问题