Check if file GT 1k

  • I'm checking the latest file created in a folder, and if it's GT than 1K ... I'm going to do further processing..

    Is this a correct way to check that?

    Thanks.

     

    $path = '\\uprd\pub\zebr\performance\dblocks\'

    $file = Get-ChildItem -Path $Path |?{-not $_.PsIsContainer} | Sort CreationTime | Select -Last 1

    Write-Output "The most recently created file is $($file.Name)"

    If ($file.Length/1024 -gt 1KB)
    ....
  • Bruin wrote:

    I'm checking the latest file created in a folder, and if it's GT than 1K ... I'm going to do further processing..

    Is this a correct way to check that?

    Thanks.

    $path = '\\uprd\pub\zebr\performance\dblocks\'
    $file = Get-ChildItem -Path $Path |?{-not $_.PsIsContainer} | Sort CreationTime | Select -Last 1

    Write-Output "The most recently created file is $($file.Name)"
    If ($file.Length/1024 -gt 1KB)
    ....

    Try it and compare what DOS says.  It's that easy.

     

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • If ($file.Length -gt 1024)   -- Worked.

    Thanks

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply