powershell - PowerShell - 将 zip(或任何)文件拆分为多个文件 - 脚本不起作用
问题描述
function split($inFile, $outPrefix, [Int32] $bufSize){
$stream = [System.IO.File]::OpenRead($inFile)
$chunkNum = 1
$barr = New-Object byte[] $bufSize
while( $bytesRead = $stream.Read($barr,0,$bufsize)){
$outFile = "C:\OutDir\$outPrefix$chunkNum"
$ostream = [System.IO.File]::OpenWrite($outFile)
$ostream.Write($barr,0,$bytesRead);
$ostream.close();
echo "wrote $outFile"
$chunkNum += 1
}
}
split "C:\File_To_Split.iso" "Splits_" "10240000"
我有上面的脚本,我正在尝试开始工作。我需要将一个 1.5GB 的 zip 文件拆分为 100 多个迷你文件,然后在它们被移动后将它们重新组合在一起。
当我运行上面的脚本时,它什么也没做。显然,我正在处理事情。谁能看到我往南走的地方?
问候,-罗恩
解决方案
您需要在定义后调用该split
函数。
添加以下内容:
split -inFile $inFile -outPrefix "prefixGoesHere" -bufSize 4MB
在脚本底部的新行上。更改"prefixGoesHere"
和4MB
为您要传递的适当值。
如果您希望能够将参数传递给脚本本身,请在param
脚本顶部添加一个块,然后将参数传递给split
函数:
param(
[string]$inFile = "C:\InnoWake\Server\MiningServer.zip",
[string]$outPrefix = "",
[int]$bufSize = 4MB
)
function split($inFile, $outPrefix, [Int32] $bufSize){
$stream = [System.IO.File]::OpenRead($inFile)
$chunkNum = 1
$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
}
}
# splatting the $PSBoundParameters variable will pass all the parameter arguments that were originally passed to the script, to the `split` function
split @PSBoundParameters
推荐阅读
- node.js - 在 Node 10 中混淆安装错误与 ifxnjs
- python - 出于神秘原因,函数为 numpy 数组定义了一个不需要的属性
- mysql - 如何添加多列并显示最大值?
- r - 将单独文件中的试验叠加到一个 ggplot 图上
- sql-server - SQL Server docker容器在初始化后停止
- c++ - 从字符串转换为 uint8,反之亦然
- javascript - 从字符串返回最大的 3 位数块 - JavaScript
- r - 如何使用关于来自两个不同数据帧的两列的 if else 语句创建新列?
- linkedin - 在哪里申请访问 LinkedIn r_fullprofile 的权限?
- php - 拉拉维尔。setRelation(s) - 只添加最后一个关系