
1 fenglala 2023 年 2 月 17 日 via Android |
2 mudssky 2023 年 2 月 17 日 避免多次读取和写入同一个文件。可以将已存在的文本内容加载到变量中,并将新内容添加到变量中,然后一次性将变量写入文件。这样可以减少磁盘 I/O 操作,提高执行速度。例如: $cOntent= Get-Content 888.txt -Raw Get-ChildItem -Path "C:\Path\To\Directory" -Recurse -ErrorAction SilentlyContinue | ForEach-Object { if ($_.Attributes -ne "Directory") { $newCOntent= Get-Content $_.FullName -Raw if ($newContent -notin $content) { $content += $newContent } } } Set-Content 888.txt -Value $content -Encoding utf8 帮你查的 |
3 darklights 2023 年 2 月 17 日 空间换时间 $dict = @{}; gc a.txt | ?{$_ -notmatch '^\s*$'} | %{$dict[$_]=1} gc b.txt | ?{$_ -notmatch '^\s*$'} | ?{-not $dict[$_]} | Add-Content a.txt |
4 1054850490 OP @fenglala 但是这个并不是 powershell ,而是 bash |