by sukans1995 at 2013-05-03 13:21:13
I would like an easy way to find out for a given path along with filters like "c:\windows|*.txt" as a parameter, the number of lines in each file, along with filenameby ArtB0514 at 2013-05-03 13:50:27
Output will be like
Filename Total lines
===========================
name1.txt 300
name2.txt 10
name3.txt 40
Thanks
Sukanya
#requires PowerShell V3.0
$FileData = @()
Get-ChildItem c:\Windows -Include *.txt | ForEach-Object {
$FileData += [pscustomobject]@{'FileName'=$.Name;'Total Lines'=(Get-Content $.FullName).Count}
}
or this for any version of PowerShell:$FileData=@()
Get-ChildItem C:\Windows -Include *.txt | ForEach-Object {
$FileData += New-Object PSObject -Property @{'FileName'=$.Name;'Total Lines'=(Get-Content $.FullName).Count}
}