PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 28, 2022

[FIXED] What is the fastest way to retrieve the header names from csv files

 August 28, 2022     csv, powershell     No comments   

Issue

I am trying to organize the column names by retrieving the unique header names of the csv files.

I used the following the code to retrieve the header names, but this script response is not fast when I have large size or millions of csv files in directories & subdirectories.

$files = Get-ChildItem "F:\MY_DATA\ASUSH" -Recurse
foreach ($f in $files) {
if ($f -Like "*.csv") {
  echo $f.FullName
  $Data=Get-Content -Path $f.FullName
  echo $Data[0]
}
}

What is the fastest way to retrieve the csv file header names?


Solution

Get-Content has a -TotalCount parameter that will only read a certain number of lines.

$Data = Get-Content -Path $f.Fullname -TotalCount 1

That should speed things up.



Answered By - James Parr
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing