【发布时间】:2016-01-19 11:11:22
【问题描述】:
我为删除特定目录编写了这个命令:
Get-ChildItem M:\ -recurse -Directory -Exclude images,record |
Where-Object { $_.CreationTime -lt (Get-Date).AddDays(-90) } |
Select-String "\d{8}" |
Remove-Item -Recurse -WhatIf -ErrorAction Stop
但我收到此错误:
Remove-Item : 找不到路径“C:\delete_old_pics\InputStream”,因为它确实存在
不存在。
在行:1 字符:151
+ ... 环 "\d{8}" | Remove-Item -Recurse -WhatIf -ErrorAction 停止
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\delete_old_pics\InputStream:String) [Remove-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
有人帮我解决这个问题吗?
编辑#1(添加目录输出 - 搜索正常):
M:\S6-仓库\20151016 M:\S6-仓库\20151017 M:\S6-仓库\20151018 M:\S6-仓库\20151019 M:\S6-仓库\20151020 M:\S6-仓库\20151021
编辑 #2
使用另外一个参数:
| Select -ExpandProperty Line之前
| Remove-Item -Force
还有 Ansgar 的建议
【问题讨论】:
-
Select-String "\d{8}"的意义何在?它将返回匹配对象。您在寻找只有 8 位数字的文件夹吗? -
请看上面:)
标签: powershell directory get-childitem