0

My users were manually backing up a huge file every day. I automated this process by creating a DOS Batch script, but the command line window does not display the slow progress for this process. Can a GUI version for this process be created which shows the same progress bar displayed when you manually copy and paste a large file?

Joe R.
  • 2,032
  • 4
  • 36
  • 72

1 Answers1

1

If you copy (or anyhow else you process) files one-by-one, you can do this.

And if you copy files using wildcard mask, (copy c:\* d:\), you can't

Progressbars in powershell are done like this:

$local:fileList = @( Get-ChildItem -Recurse -Path 'd:\_MEDIA\VIDEO' | Where-Object {$_.psIsContainer -eq $false} )
$local:fileTotalSize = $( $local:fileList | Measure-Object -Property 'Length' -Sum).Sum
$local:currentlyProcessedBytes = 0;
$local:onePercentSize = $local:fileTotalSize / 100
$local:progressActivity = 'Making backup'

ForEach ($file in $local:fileList ) {
    Write-Progress -Activity $local:progressActivity -Status "Processing $($file.Name)" -PercentComplete $( [math]::Floor( $local:currentlyProcessedBytes / $local:onePercentSize) )
    Write-Host "Working with file [$($file.FullName)]"
    #work
        #Placeholder for do some job with file
        Start-Sleep -Milliseconds 300
    $local:currentlyProcessedBytes += $file.Length

}

Write-Progress -Activity $local:progressActivity -Completed

There is a guy, that made an chimera of robocopy ad powershell

If you have one-big-file, use RoboCopy - it will show percentage

robocopy D:\_Media\Video d:\ "The.Boy.In.The.Striped.Pajamas.barm.*"
Community
  • 1
  • 1
filimonic
  • 3,988
  • 2
  • 19
  • 26
  • ok, so could you please edit your PS script to copy C:\abc,vhd to E:\ , then tell me how I can execute the script by clicking on a desktop shortcut?.. I'd like to test your suggested solution, thanks! – Joe R. Feb 01 '15 at 10:14
  • In case of one-big-file it will not work - the progress bar can be updated between copy operations. In case of one-big file use RoboCopy.exe. Updated in aswer – filimonic Feb 01 '15 at 10:22
  • There's actually two files that will ne copied from C:\ to a flash drive (E:\). The first file is ~980MB and the other is a small 14K file.Users need a frequently updated progress bar to know the status of the operation. – Joe R. Feb 01 '15 at 10:55
  • It would be wonderful if one could manually do the copy/paste with the mouse, while recording it as a macro, then execute the macro as needed. – Joe R. Feb 01 '15 at 15:13
  • It's late to the party but you can use the following to add a timer/progress bar to a powershell script, [here](http://stackoverflow.com/questions/13333223/write-progress-for-10-minutes-powershell) – user4317867 Mar 10 '15 at 04:34