Select file based on file name order

Welcome Forums General PowerShell Q&A Select file based on file name order

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 4 months ago.

  • Author
  • #33708

    Topics: 13
    Replies: 25
    Points: 28
    Rank: Member


    I am working on a script to process data on some flat files and I need a way to select just the first file in the directory where the files are located based on the name of the file. the files will be ordered alphabetically. Once the file is process it is removed from the directory so later in my script I look to see if there is still files in the directory and process again if there are.
    As always thanks for the assistance!!!

  • #33709

    Topics: 9
    Replies: 2322
    Points: 0
    Rank: Member

    Sort-Object and Select-Object should do the trick:

    $firstFile = Get-ChildItem c:\SomeFolder | Sort-Object -Property Name | Select-Object -First 1

The topic ‘Select file based on file name order’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort