0

So, I have a folder that is repeated in a directory in many different folders and I want to avoid having to code every single folder location. I just want to delete all of them from all places in 1 line, if that's possible. Here's what I have so far:

Remove-Item -Path "C:\Users\dwilson\Desktop\HTFS_v3.9_201511193\Databases" -Filter *onetimescripts* -force -Recurse -ErrorAction SilentlyContinue -Verbose

The error it returns is:

 Remove-Item : Cannot remove item 
    C:\Users\dwilson\Desktop\HTFS_v3.9_201511193\Databases\HTFSJob\BAM\onetimescripts: 
     The directory is not empty.
At line:1 char:1
+ Remove-Item -Path "C:\Users\dwilson\Desktop\HTFS_v3.9_201511193\Databases" -Filt 
...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (onetimescripts:DirectoryInfo) [Remove-It 
   em], IOException
    + FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Comm 
   ands.RemoveItemCommand

I feel like this is probably a very simple fix, but I'm not able to find it.

4

1 回答 1

0

答案是:

Get-ChildItem -Path "C:\path" -Name "foldername" -Directory -Recurse | Remove-Item -Force -Recurse
于 2015-11-24T16:39:45.650 回答