resolved input-csv random file-names

Welcome Forums General PowerShell Q&A resolved input-csv random file-names

This topic contains 4 replies, has 3 voices, and was last updated by  David Schmidtberger 3 years, 11 months ago.

  • Author
    Posts
  • #21877

    Participant
    Points: 38
    Rank: Member

    I've been looking and trying to figure out how to use input-csv to grab any csv file within a specified folder.

    need to run a script against csv files that will have different file-names every-time.

    any ideas?

  • #21878

    Member
    Points: 0
    Rank: Member

    You can just use Get-ChildItem *.csv to find the files, and then import them inside a loop. Something like this:

    Get-ChildItem c:\SomeFolder\*.csv |
    ForEach-Object {
        $file = $_
        $data = Import-Csv -Path $file.FullName
        # Do something with the data in $file
    }
    
  • #21880

    Participant
    Points: 38
    Rank: Member

    was hoping for a little easier method, as it will only ever be 1 file in the input file location, i will then move the file out after processing.

    get-childitem seemed a little more complex than needed

  • #21881

    Participant
    Points: 38
    Rank: Member

    never mind i should have just tried it. didn't think it actually would be as easy as *.csv

    somedays you over-think things

The topic ‘resolved input-csv random file-names’ is closed to new replies.