Created
June 21, 2022 10:43
-
-
Save Callumpy/d8d46a407ccde993b581b3edbd7d5679 to your computer and use it in GitHub Desktop.
Get a count of CSV files in a folder structure and count how many rows of data in each CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd $PSScriptRoot | |
$rootFolder = 'C:\DefaultRoot\' | |
$files = Get-ChildItem -Path ($rootFolder + "*.csv") -Recurse | |
$output = foreach ($file in $files) { | |
try { | |
[int]$LinesInFile = 0 | |
$reader = New-Object IO.StreamReader ($file.DirectoryName + "\" + $file.Name) | |
while($reader.ReadLine() -ne $null){ $LinesInFile++ } | |
[PSCustomObject]@{ | |
'name' = $file.Name; | |
"directory" = $file.DirectoryName; | |
"lastWriteTime" = $file.LastWriteTimeUtc; | |
"lastAccessTime" = $file.LastAccessTimeUtc; | |
"lines" = $LinesInFile | |
} | Export-Csv <LOCATION>\files.csv -notype -Append | |
} catch {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment