鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 服务器相关 > 批处理 > >

Powershell分割文件

来源:互联网 作者:佚名 时间:2015-11-13 08:11
Powershell分割文件 http://www.brangle.com/wordpress/2009/08/combine-join-two-text-files-using-powershell/ Powershell function split($inFile, $outPrefix, [Int32] $bufSize){ $stream = [System.IO.File]::OpenRead($inFile) $chunkNum = 1 [Int64]$
Powershell分割文件
http://www.brangle.com/wordpress/2009/08/combine-join-two-text-files-using-powershell/ Powershell
function split($inFile,  $outPrefix, [Int32] $bufSize){

  $stream = [System.IO.File]::OpenRead($inFile)
  $chunkNum = 1
  [Int64]$curOffset = 0
  $barr = New-Object byte[] $bufSize

  while( $bytesRead = $stream.Read($barr,0,$bufsize)){
    $outFile = "$outPrefix$chunkNum"
    $ostream = [System.IO.File]::OpenWrite($outFile)
    $ostream.Write($barr,0,$bytesRead);
    $ostream.close();
    echo "wrote $outFile"
    $chunkNum += 1
    $curOffset += $bytesRead
    $stream.seek($curOffset,0);
  }
}
Get-Content bigfile.bin -ReadCount 100MB -Encoding byte
copy /b file1.bin+file2.bin+file3.bin combined_files.bin
New-Item -ItemType file ".\combined_files.txt" –force
Get-Content .\file?.txt | Add-Content .\combined_files.txt
网友评论
<