Created
April 26, 2019 14:33
-
-
Save gitfvb/108fc151cb8716a10fa59980842e1858 to your computer and use it in GitHub Desktop.
Function to split a file into parts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Split-File{ | |
param( | |
$inFile, | |
$outPrefix, | |
[Int32] $bufSize | |
) | |
$file = Get-Item -Path $inFile | |
$stream = [System.IO.File]::OpenRead($inFile) | |
$chunkNum = 1 | |
$barr = New-Object byte[] $bufSize | |
while( $bytesRead = $stream.Read($barr,0,$bufsize)){ | |
$outFile = "$( $file.DirectoryName )\$( $file.Name ).$( $outPrefix )$( $chunkNum )" | |
$ostream = [System.IO.File]::OpenWrite($outFile) | |
$ostream.Write($barr,0,$bytesRead); | |
$ostream.close(); | |
#echo "wrote $outFile" | |
$chunkNum += 1 | |
} | |
} | |
Split-File -inFile "<file>" -outPrefix "part" -bufSize 100000 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment