locked
Progress of GCI -Recurse RRS feed

  • Question

  • Is it possible to display the progress of GCI -Recurse, when trying to enumerate a huge file system?

    I see examples on creating a progress bar, but all I find are ones that process the contents after GCI is finished, I would like to have a progress bar, while GCI is retrieving the huge file system.


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    Thursday, November 8, 2012 4:15 PM

Answers

  • The problem with this is that Write-Progress needs a percentage.  This can only be calculated after you have counted all the files (gci), which is kind of going round in circles.

    Grant Ward, a.k.a. Bigteddy

    • Marked as answer by clayman2 Thursday, November 8, 2012 4:47 PM
    Thursday, November 8, 2012 4:43 PM
  • Not exactly a progress bar, but in the same vein:

    function time_pipeline { 
    param ($increment  = 1000) 
    begin{$i=0;$timer = [diagnostics.stopwatch]::startnew()} 
    process { 
        $i++ 
        if (!($i % $increment)){Write-host “`rProcessed $i in $($timer.elapsed.totalseconds) seconds” -nonewline} 
        $_ 
        } 
    end { 
        write-host “`rProcessed $i files in $($timer.elapsed.totalseconds) seconds” 
        Write-Host "   Average rate: $([int]($i/$timer.elapsed.totalseconds)) files/sec." 
        } 
    } 
    get-childitem <path> -Recurse | time_pipeline | set-variable files


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Marked as answer by Yan Li_ Tuesday, November 13, 2012 3:10 AM
    Friday, November 9, 2012 3:53 AM

All replies

  • The problem with this is that Write-Progress needs a percentage.  This can only be calculated after you have counted all the files (gci), which is kind of going round in circles.

    Grant Ward, a.k.a. Bigteddy

    • Marked as answer by clayman2 Thursday, November 8, 2012 4:47 PM
    Thursday, November 8, 2012 4:43 PM
  • I kind of figured that, thanks Bigteddy

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    Thursday, November 8, 2012 4:47 PM
  • Although they don't make it explicitly clear, Write-Progress was implemented so you can jump around the entire percentage-and-seconds thing and turn it into a Perl-esque progress bar. Here's a quick demo:

    $indicator = "";
    $indicatorCharacter = "."
    for($i = 0; $i -lt 200; $i++){
    Start-Sleep -Milliseconds 20;
    $indicator += $indicatorCharacter
    Write-Progress -Activity "File enumeration; each '$indicatorCharacter' represents 200 files." -Status $indicator
    }
    
    

    (I MAY be wrong when I say "...was implemented so you can jump around..." - but it vaguely rings a bell.)
    Friday, November 9, 2012 3:19 AM
  • Not exactly a progress bar, but in the same vein:

    function time_pipeline { 
    param ($increment  = 1000) 
    begin{$i=0;$timer = [diagnostics.stopwatch]::startnew()} 
    process { 
        $i++ 
        if (!($i % $increment)){Write-host “`rProcessed $i in $($timer.elapsed.totalseconds) seconds” -nonewline} 
        $_ 
        } 
    end { 
        write-host “`rProcessed $i files in $($timer.elapsed.totalseconds) seconds” 
        Write-Host "   Average rate: $([int]($i/$timer.elapsed.totalseconds)) files/sec." 
        } 
    } 
    get-childitem <path> -Recurse | time_pipeline | set-variable files


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Marked as answer by Yan Li_ Tuesday, November 13, 2012 3:10 AM
    Friday, November 9, 2012 3:53 AM