Re: When reporting transfer progress, access overall & current file size?
Somehow that only prints zeros. That is, decimal places will always be: .00
Strange. It works for me. With your exact code.
Somehow that only prints zeros. That is, decimal places will always be: .00
Anyway, I have added this request to the tracker
To print$transferredSizeLocal / 1MB
with decimal places, just replaceN0
with number of decimal places you want to show, e.g.N2
.
$transferredSizeLocal / 1MB
with decimal places, just replace N0
with number of decimal places you want to show, e.g. N2
.
…
foreach ($file in $remoteFiles) {
$Script:sizeFile = $file.Length
$session.GetFiles("$file.Name", "$localPath", $false, $transferOptions).Check()
$Script:sizeTransferred += $file.Length
}
…
function FileTransferProgress {
param($e)
$transferredSizeLocal = $e.FileProgress * $Script:sizeFile + $Script:sizeTransferred
$pgBar.Value = [int](100 * $e.OverallProgress)
$pgBar.OverlayText = ("[{0:N0}/{1:N2} MB] {2}" -f ($transferredSizeLocal / 1MB), ($Script:sizeTotal / 1MB), (Split-Path -Path $e.FileName -Leaf))
$pgBar.Refresh()
[System.Windows.Forms.Application]::DoEvents()
}
$transferredSizeLocal
with decimal places since $e.FileProgress * $Script:sizeFile
seems to cast the variable into an integer.
but that doesn't quite seem to work.
Session.FileTransferProgress
's event offers FileProgress
and OverallProgress
, but is there a way to also retrieve FileSize
and OverallSize
?
{Get,Put}FilesToDirectory
that don't require one's code to individually reference files to be transferred.
"[ $total_transferred_size / $total_overall_size ] $current_filename ]"
status line underneath. The former is trivial, but the latter is a mess.
(Get-Item $file.FullName).Length
$files = $session.EnumerateRemoteFiles
$file.Length
$total_overall_size
and keeping track of $total_transferred_size
during the individual transfers, but that doesn't quite seem to work.