abstract

The concern is documenting the usage of array object to count lines of files stored there

contents

1. command

dir $arr -Recurse -File  |  foreach{(GC $_) | Measure-Object -Line}

2. result

  • this is an array
$arr = @(
"action_point_1.json",
"entry_point_1.json",
"yoti_av_1.json",
"custom_key_value_1.json",
"failure_1.json",
"check_requested_1.json",
"entry_point_1.json",
"error_response_code_1.json",
"media_basic_1.json",
"task_requested_1.json",
"link_tid_uid_1.json",
"attribute_1.json",
"envelope_essentials_1.json"
)
  • this is the output → note the nested pipe that had to be done within the foreach loop in order to get this right and not aggregated
dir $arr -file -rec | % {(Get-Content $_) | Measure-Object -Line}

Lines Words Characters Property
----- ----- ---------- --------
   16
   16
   16
   16
   16
   16
   16
   16
   16
   16
   16
   16
   16

sum lines

  • without nesting the sum is aggregated
 dir $arr -file -rec | Get-Content | Measure-Object -Line

Lines Words Characters Property
----- ----- ---------- --------
  256

better formatting

 dir $arr -recurse | select Fullname,@{name="LineCount";expression={ @(get-content $_.fullname).count }}

FullName                                                  LineCount
--------                                                  ---------
C:\temp\com.provemyage.client\action_point_1.json         16
C:\temp\com.provemyage.client\entry_point_1.json          16
C:\temp\com.yoti.docscan_server\entry_point_1.json        16
C:\temp\com.provemyage.server\yoti_av_1.json              16
C:\temp\com.yoti.agescan_server\custom_key_value_        16
C:\temp\com.yoti.agescan_server\failure_1.json            16
C:\temp\com.yoti.docscan_server\check_requested_1        16
C:\temp\com.provemyage.client\entry_point_1.json          16
C:\temp\com.yoti.docscan_server\entry_point_1.json        16
C:\temp\com.yoti.docscan_server\error_response_co        16
C:\temp\com.yoti.docscan_server\media_basic_1.json        16
C:\temp\com.yoti.docscan_server\task_requested_1.        16
C:\temp\com.yoti.main_mobile_app\link_tid_uid_1.j        16
C:\temp\com.yoti.mobile_app\link_tid_uid_1.json           16
C:\temp\com.yotisign.server\attribute_1.json              16
C:\temp\com.yotisign.server\envelope_essentials_1        16

3. sources