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

标签 regex powershell match

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

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/

相关文章:

java - 替换java中的撇号 ' in the middle of the word with\'

authentication - Powershell BitsTransfer https基本身份验证语法

python - 如何测试多个变量与单个值的相等性?

arrays - 在 Perl 中,是否有内置方法来比较两个数组是否相等?

python - 如何在 Python 中使用正则表达式排除特定字符串?

java - 我想用逗号分隔符按列拆分 SQL 查询。但有些数据类型里面有逗号。需要排除那些逗号

powershell - 像数组一样对 powershell Import-Csv 行进行索引

python - Azure Powershell 中出现异常 'File not found' pscloudshell 错误

python - 在多个条件下匹配 2 个 dfs

python - 通过正则表达式在 Python 中对字符串进行分区