Skip to content

Instantly share code, notes, and snippets.

@mcc85s
Created September 8, 2023 20:47
Show Gist options
  • Save mcc85s/6ca200a3bbca0ebfd0bede7ae81c9cb4 to your computer and use it in GitHub Desktop.
Save mcc85s/6ca200a3bbca0ebfd0bede7ae81c9cb4 to your computer and use it in GitHub Desktop.
Class PercentProgress
{
[DateTime] $Start
[DateTime] $Now
[DateTime] $End
[Float] $Percent
[TimeSpan] $Elapsed
[TimeSpan] $Remain
[TimeSpan] $Total
PercentProgress([String]$Start)
{
$This.Start = [DateTime]$Start
}
[Object] GetPercent([Float]$Percent)
{
$This.Now = [DateTime]::Now
$This.Elapsed = [TimeSpan]($This.Now-$This.Start)
$This.Percent = $Percent
$This.Total = [TimeSpan]::FromSeconds(($This.Elapsed.TotalSeconds/$This.Percent)*100)
$This.Remain = $This.Total - $This.Elapsed
$This.End = [DateTime]($This.Now + $This.Remain)
Return $This
}
}
# Suppose the file is located at "C:\Users\user\Download\download.zip"
$File = [System.IO.FileInfo]::new("C:\Users\user\Download\download.zip")
$Progress = [PercentProgress]::New($File.CreationTime.ToString("MM/dd/yyyy HH:mm:ss"))
$Progress.GetPercent(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment