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

 
Member
2 years, 9 months ago.

  • Author
    Posts
  • #33708

    Participant
    Points: 0
    Rank: Member

    Hello,

    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

    Member
    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.