-
-
Save zoellner/374f61acc982aecb1e0d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Modified from: http://stackoverflow.com/a/11010158/215200 | |
$fromFolder = "D:\FOLDER\" | |
$rootName = "FILENAME" | |
$ext = "EXT" | |
$numFiles = 16 | |
$from = "{0}{1}.{2}" -f ($fromFolder, $rootName, $ext) | |
$fromFile = [io.file]::OpenRead($from) | |
$fileSize = (Get-Item $from).length | |
$upperBound = $fileSize/$numFiles | |
$buff = new-object byte[] $upperBound | |
$count = $idx = 0 | |
try { | |
"Splitting $from into $numFiles files using $upperBound bytes per file." | |
do { | |
$count = $fromFile.Read($buff, 0, $buff.Length) | |
if ($count -gt 0) { | |
$to = "{0}{1}.{2}.{3}" -f ($fromFolder, $rootName, $idx, $ext) | |
$toFile = [io.file]::OpenWrite($to) | |
try { | |
"Writing to $to" | |
$tofile.Write($buff, 0, $count) | |
} finally { | |
$tofile.Close() | |
} | |
} | |
$idx ++ | |
} while ($count -gt 0) | |
} | |
finally { | |
$fromFile.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment