我想看看是否有任何行包含“较新”和/或“新文件”一词。我尝试过如下脚本,但没有运气。任何见解将不胜感激。
RoboCopy.exe "C:\Folder" "C:\Folder2" *.* /S /E /MIR /MT:8 /X /V /TS /FP /BYTES /ETA /LOG:C:\Output\log\sync.txt
$SourceDir = "C:\Output\log\"
#$GCI_Fiter = '*.txt'
$Include=@("*.txt")
$FileList = Get-ChildItem -LiteralPath $SourceDir -Include "$Include" -File
foreach ($FL_Item in $FileList) {
$results = Get-Content -Path $FL_Item.FullName | Select-String -pattern '(newer.New File)'
}
Robocopy 日志:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Wednesday, December 25, 2019 8:16:28 PM
Source : C:\Folder\
Dest : C:\Folder2\
Files : *.*
Options : *.* /V /X /TS /FP /BYTES /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /ETA /MT:8 /R:1000000 /W:30
------------------------------------------------------------------------------
New File 1 2019/12/25 17:16:04 C:\Folder\2.txt
same 0 2019/12/25 11:38:23 C:\Folder\2\1.txt
same 24 2019/09/25 08:42:17 C:\Folder\5.csv
Newer 1 2019/12/25 17:16:04 C:\Folder\4.txt
100%
same 0 2019/12/11 08:06:39 C:\Folder\1.txt
same 0 2019/12/11 08:06:39 C:\Folder\2.txt
------------------------------------------------------------------------------
最佳答案
如果您使用 Get-Content
将该文件加载到 $InStuff
中,则可以使用 -match
处理集合的方式。这将为您提供与正则表达式模式匹配的行。像这样...
$InStuff -match 'newer|new file'
输出...
New File 1 2019/12/25 17:16:04 C:\Folder\2.txt
Newer 1 2019/12/25 17:16:04 C:\Folder\4.txt
关于Powershell 获取内容中的多重匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59480526/