您现在的位置是:网站首页> 编程资料编程资料
Powershell学习笔记--使用正则表达式查找文件_PowerShell_
2023-05-26
362人已围观
简介 Powershell学习笔记--使用正则表达式查找文件_PowerShell_
支持所有PS版本
Get-ChildItem 不支持文件高级筛选。它只能使用简单的通配符,但不能使用正则表达式。
围绕这个问题,我们可以使用-match命令来筛选。
下面这个例子将获得所有windows目录下包含至少连续有两个数字的文件同时文件名长度不超过8个字符:
Get-ChildItem -Path $env:windir -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.BaseName -match '\d{2}' -and $_.Name.Length -le 8 } 注意文件的属性”BaseName”是没有包括扩展名的,这样数字出现在扩展名将不会被统计。
您可能感兴趣的文章:
相关内容
- Tornado中database模块被取消的替代方法_PowerShell_
- Powershell直接脚本时出现无法加载文件因为禁止执行脚本_PowerShell_
- PowerShell是什么?_PowerShell_
- PowerShell中正则表达式使用例子_PowerShell_
- PowerShell中调用外部程序和进程操作命令例子_PowerShell_
- 使用PowerShell操作Windows服务的命令小结_PowerShell_
- PowerShell遍历文件、文件夹的方法_PowerShell_
- PowerShell中使用Test-Path命令检查文件或文件夹路径是否存在示例_PowerShell_
- PowerShell读取文件内容、替换文件内容、读取限定行的例子_PowerShell_
- PowerShell中把IP转换为长整形数字的方法_PowerShell_
