You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell中如何删除.vs文件夹?已尝试脚本无效求解决

解决PowerShell删除.vs文件夹的问题

你可以试试以下几种可行的写法:

方法一:使用-Filter参数(更高效)

Get-ChildItem $map -Recurse -Filter ".vs" -Directory | Remove-Item -Force -Recurse

方法二:修正-Include的使用方式

如果坚持用-Include,需要在目标路径后加上\*,让PowerShell递归查找所有子项:

Get-ChildItem "$map\*" -Recurse -Include ".vs" -Directory | Remove-Item -Force -Recurse

方法三:通过Where-Object筛选文件夹名称

Get-ChildItem $map -Recurse -Directory | Where-Object { $_.Name -eq ".vs" } | Remove-Item -Force -Recurse

为什么之前的脚本没效果?

  • 当Get-ChildItem搭配-Recurse和-Include使用时,如果指定的目标路径($map)是单个目录,PowerShell只会检查该目录本身是否匹配-Include规则,不会自动遍历子目录内的项。加上\*后,才会触发对目标目录下所有子项的递归查找。
  • -Directory参数可以替代Where-Object {$_.PSIsContainer},写法更简洁直接。

内容的提问来源于stack exchange,提问作者Eric

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 12:04:50