Skip to content

Instantly share code, notes, and snippets.

@gitfvb
Created April 26, 2019 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitfvb/108fc151cb8716a10fa59980842e1858 to your computer and use it in GitHub Desktop.
Save gitfvb/108fc151cb8716a10fa59980842e1858 to your computer and use it in GitHub Desktop.
Function to split a file into parts
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