を実行しているここで私は、フォルダ内のすべてのテキストファイル(1つずつ)の先頭に「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ギガバイトを超えるごとに、このコードを実行しています。
私はこの問題を解決するにはどうすればよいですか?ヘッダファイルをコピーする+新しいファイルに大きなファイルは(そのサイズのファイルの場合)のOutOfMemory例外を起こしにくいだろう
これを試しましたか?何か必要なものはありません。 –
@RomanKuzmin私は、out-fileコマンドレットでエンコーディングを忘れました。キャッチするためにありがとう。大きなファイル(> 2GB)でテストしてもうまく動作します(<1分) –
ヘッダーファイルのエンコーディングは、test_export.txtファイルのエンコーディングと一致する必要があります。 –