Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Loop through a list of CSV files in Powershell

This is a simple question so I hope you can help me.
I have a list of 150 CSV files called file1, file2, file3 etc..
I need to run a Powershell script going through every file
Right now im doing this manually by every CSV with this.

Import-Csv .\PD\file1.csv | .\script.ps1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use Get-ChildItem to discover the files on disk, then use ForEach-Object to process them 1 by 1:

Get-ChildItem path\to\directory -File -Filter *.csv |ForEach-Object {
  Import-Csv $_.FullName | .\script.ps1
}

The FullName property will contain the rooted path to the file, eg. C:\path\to\PD\file1.csv

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading