resolved input-csv random file-names

This topic contains 4 replies, has 3 voices, and was last updated by  David Schmidtberger 1 year, 10 months ago.

  • Author
    Posts
  • #21877
    Profile photo of David Schmidtberger
    David Schmidtberger
    Participant

    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
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of David Schmidtberger
    David Schmidtberger
    Participant

    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
    Profile photo of David Schmidtberger
    David Schmidtberger
    Participant

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

    somedays you over-think things

You must be logged in to reply to this topic.