gpt4 book ai didi

regex - Powershell 模式匹配正则表达式

转载 作者:行者123 更新时间:2023-12-02 23:15:42 24 4
gpt4 key购买 nike

在我们的服务器上,我们有类似于以下的文件:

C:\Documents and Settings\username\Application Data\Sun\Java\jre1.6.0_01\
C:\Documents and Settings\username\Application Data\Sun\Java\jre1.6.0_02\
C:\Documents and Settings\username\Application Data\Sun\Java\jre1.6.0_03\
etc

我们不再需要这些文件,所以我正在尝试编写一个 powershell 脚本来删除它们。现在我将自己限制在一台特定的服务器上,并且我有以下脚本:
 $path = "\\server\c$\Documents and Settings\"
Get-ChildItem $path -Recurse | Where {$_.PSIsContainer -and ($_ -match '^jre1.6.0_')} | Remove-Item -Recurse -WhatIf

问题是我使用的模式似乎没有调用匹配,我不确定我做错了什么。我已经尝试了几种排列,但似乎都没有。那里的任何正则表达式大师都可以阐明我可能做错了什么吗?

谢谢
布拉德

最佳答案

试试这样:

Get-ChildItem $path -Recurse -Force | ....
-Force还查找隐藏或系统文件/文件夹。

“应用程序数据”文件夹已隐藏!

关于regex - Powershell 模式匹配正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10486416/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com