当这里是我使用添加“segment99”到一个文件夹中的所有文本文件(逐个)开头的PowerShell脚本:OutOfMemoryException异常运行我的PowerShell脚本
Set Environmental Variables:
$PathData = '<<ESB_Data_Share_HSH>>\RwdPnP'
Go to each text file in the specified folder and add header to the file:
Get-ChildItem $PathData -filter 'test_export.txt'|%{
$content = '"segment99" ' + [io.file]::ReadAllText($_.FullName)
[io.file]::WriteAllText(($_.FullName -replace '\.txt$','_99.txt'),$content)
}
这是给我的以下错误:
Error: Exception calling "ReadAllText" with "1" argument(s): "Exception of type 'Syste
Error: m.OutOfMemoryException' was thrown."
Error: At D:\apps\MVPSI\JAMS\Agent\Temp\JAMSTemp13142.ps1:17 char:51
Error: + $content = '"segment99" ' + [io.file]::ReadAllText <<<< ($_.FullName)
Error: + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
Error: + FullyQualifiedErrorId : DotNetMethodException
Error:
我在具有20个文件的文件夹上运行此代码,每个文件超过2 GB。
我该如何解决这个问题?
你试试这个?它做了一些事情,但没有什么需要... –
@RomanKuzmin我忘记了out-file cmdlet中的编码。感谢您的支持。测试在一个大文件(> 2GB)和效果相当好(<1分钟) –
只要是明确的,头文件的编码应当匹配test_export.txt文件的编码。 –