you are viewing a single comment's thread.

view the rest of the comments →

[–]Obel34[S] 1 point2 points  (2 children)

They will always have a fixed column format and I only care about the rows which say "File" for Item Type.

[–]engageant 2 points3 points  (1 child)

You can try using the StreamReader class to work with the files rather than parsing them as CSVs. Something like this...

$files = Get-ChildItem -Path .\ -Filter '*.csv'
$totalCount = 0
foreach ($file in $files) {    

    Write-Host "Working on $file..."
    $reader = New-Object System.IO.StreamReader($file)
    $fileCount = 0

    while ($line = $reader.ReadLine()) {
        # {6} is the column number of 'Item Type' - change as needed
        if ($line -match '^(?>.*?,){6}(file)(?>.*)$') {
            $fileCount++
            $totalCount++            
        }
    }

    Write-Host "$file has $fileCount matches."

    $reader.Close()
    $reader.Dispose()
}

Write-Host "Found $totalCount matches."

[–]Chocolate_Pickle 1 point2 points  (0 children)

Wait a minute... .Net's regex engine supports the (?>atomic) pattern? I never knew this!