regex - 复制 findstr 找到的文件?
问题描述
我试图将我用 findstr 找到的文件复制到另一个文件夹。这就是我所做的,列出了我要复制的所有文件
dir * /a /b |findstr ^FALSE[0-9][0-9]\.txt$
如何将此列表重定向到复制命令?我试图不使用批处理文件。
解决方案
对我来说,这在 PowerShell 中更容易。如果您在受支持的 Windows 系统上,则可以使用 PowerShell。当您确信正确的文件将被复制到正确的位置时,请删除-WhatIf
from Copy-Item
.
Get-ChildItem -File -Path 'C:\src\t' -Filter 'FALSE*.txt' |
Where-Object { $_.Name -match '^FALSE[0-9]{2}\.txt$' } |
ForEach-Object { Copy-Item -Path $_.FullName -Destination 'C:\the\other\place' -WhatIf }
如果这仅在命令外壳中,您可以使用:
gci -File 'C:\src\t\FALSE*.txt'|?{$_.Name -match '^FALSE[0-9]{2}\.txt$'}|%{ Copy-Item $_.FullName 'C:\the\other\place' -WhatIf }
推荐阅读
- android - Android - 从搜索设备应用程序中单击应用程序后,已打开的应用程序重新打开
- ios - 我现有的 TableViewController 在 Xcode 11 beta1 上崩溃
- python - NoReverseMatch at / Reverse for 'single_product' 未找到任何参数。尝试了 1 种模式:['products/(?P
)/$'] - python - 使用 py2neo 驱动程序,如何使用 for 循环从列表中创建节点?
- symfony - 如何避免终端捕获错误而不是 Symfony 分析器
- generics - 如何使用嵌套泛型编写扩展函数?
- react-native - 如何在没有博览会的情况下在本地哨兵中上传源地图
- r - 如何在 R 中使用 tidyjson 处理嵌套的空 JSON 数组
- mysql - 使用 SQL 计算特定事件发生的百分比
- http-headers - 由于内容安全政策,Google 字体无法加载