Select file based on file name order

This topic contains 1 reply, has 2 voices, and was last updated by  Dave Wyatt 2 years, 6 months ago.

  • Author
  • #33708

    Nathan W


    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

    Dave Wyatt

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

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

You must be logged in to reply to this topic.