-1

How do i import csv files where the name is different every month.

2018-01-foo.csv 2018-01-bar.csv

And a moth later

2018-02-foo.csv 2018-02-bar.csv

Im trying to script a task.

But the files it should import have prequels that changes every month.

Cheers!

YilGul
  • 18
  • 4
  • I'm afraid I don't quite understand. Are these all in the same folder? Could you not just open the first csv in the folder. What have you tried? I would start by trying to format dates into strings which would get the names if you are going to assume they exist and there are too many to just blindly open them. – Matt Sep 27 '18 at 19:43
  • Thanks for your response.. The thing is: a third parties drops 10 files in a folder every month. And the files have a different name every month due to the month number. – YilGul Sep 27 '18 at 19:52

1 Answers1

1

Build the name as a variable, then use that to import.

$FileName = [datetime]::today.tostring('yyyy-MM') + '-foo.csv'
$DataIn = Import-Csv $FileName
TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56