所以我让代码按照我喜欢的方式在单个文件中工作。基于下面的一些建议,我想出了以下几点:
$Path = "C:\Users\User\Documents\PowerShell\"
$Num = 160
$ZipFile = "FileGroup0000000$Num.zip"
$File = "*$Num*.txt"
$n = dir -Path $Path$File | Measure
if($n.count -gt 0){
Remove-Item $Path$ZipFile
Compress-Archive -Path $Path$File -DestinationPath $Path
Rename-Item $Path'.zip' $Path'FileGroup0000000'$Num'.zip'
Remove-Item $Path$File
}
else {
Write-Output "No Files to Move for FileGroup$File"
}我现在唯一需要做的就是让$Num在每次程序结束后递增。因此,程序将运行,然后将$Num移到160、161等位置,这样我就不必手动重新启动代码了。谢谢你到目前为止的帮助。
发布于 2020-03-08 18:44:58
您的文件名格式应该放在循环中,并且应该使用Format operator -f来获取前面的零,如下所示:
159..1250 | ForEach-Object {
$UnzippedFile = 'FileGroup{0:0000000000}' -f $_
$ZipFile = "$UnzippedFile.zip"
Write-Host "Unzipping: $ZipFile"
# Do your thing here
}https://stackoverflow.com/questions/60582851
复制相似问题