Link to home
Start Free TrialLog in
Avatar of bnorrisatnortechsolutions

asked on

File Counts - Multiple Directories - Looking for certain words

I need a script that would search multiple directories for files that contain the words "performance" and then the word "experience" and return a count for each word.  

Then export the results to a CSV file that lists the results for directory 1 listing the performance files by name and then list the Experience files by name and then the total count for each type (i.e. Performance and Experience) and the same for directory 2 and so on......

The multiple directories would be listed in a DirList.txt file.

Avatar of soostibi
Flag of Hungary image

Can the "Performance" or "experience" appear in the files more than once in a specific line?
Avatar of bnorrisatnortechsolutions


The words "performance" and/or "experience" will only be in the file name once.
In the file name or within the file?
In the file name
Hope you want something like this, as the output you requested is not very structured, but I tried to put it into a table:
$where = Get-Content C:\ee\dirlist.txt

$where | %{
    $actdir = $_
    "" | Select-Object @{n="Directory"; e={"$actdir"}}, Group, Files, PerformaceFiles, ExperienceFiles 
    dir $actdir | ? {!$_.psiscontainer -and $ -match "performance|experience"} | % {$p=$e=0} {
        $file = $_ 
        switch -regex (${
            performance {$p++; $file | Add-Member -MemberType noteproperty -Name Label -Value "Performance" -PassThru }
            experience {$e++; $file | Add-Member -MemberType noteproperty -Name Label -Value "Experience" -PassThru }
    } | Group-Object -Property label | %{
        $group = $_
        "" | Select-Object Directory, @{n="Group"; e={$}}, Files, PerformaceFiles, ExperienceFiles 
        Select-Object -InputObject $_ -ExpandProperty group  | Sort-Object -Property name |
            Select-Object @{n="Directory";e={""}},group,@{n="Files";e={$}}, PerformaceFiles, ExperienceFiles 
    New-Object -TypeName PSObject -Property @{
        Directory = $actdir
        PerformaceFiles = $p
        ExperienceFiles = $e
    } | Select-Object -Property Directory, group, PerformaceFiles, ExperienceFiles 
}  | Export-Csv c:\ee\pstat.csv -NoTypeInformation -UseCulture

Open in new window

That works for all files listed in the directories.  However, I only need the results to return the files that were created yesterday and today.
You have not mentioned this before! I'll do it soon.
I apologize.  It was in my orginal post that I was going to post, but I removed it.
Avatar of soostibi
Flag of Hungary image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I posted another question if you are interested.  If not, I understand that you have a life and other things to do besides write POSH scripts for me.  I do appreciate all of your respsonses though.