所以,我有一个文件夹在许多不同文件夹的目录中重复,我想避免编码每个文件夹位置。我只是想从1行的所有地方删除所有这些,如果可能的话。这就是我到目前为止所拥有的:
Remove-Item -Path "C:\Users\dwilson\Desktop\HTFS_v3.9_201511193\Databases" -Filter *onetimescripts* -force -Recurse -ErrorAction SilentlyContinue -Verbose
它返回的错误是:
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
我觉得这可能是一个非常简单的修复,但我找不到它。
答案 0 :(得分:0)
答案是:
Get-ChildItem -Path "C:\path" -Name "foldername" -Directory -Recurse | Remove-Item -Force -Recurse