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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.