Link to home
Start Free TrialLog in
Avatar of Brian Smith
Brian Smith

asked on

How can I force the file content search to include all subdirectories?

Hi Expert,

I manage to lookup and display the full line of content of all txt file (based on the criteria below).

However, I would like:

1) the searches to include all subdirectories (not just from the root)
2) output both the the respective subfoldername * filename of detected file which contents the target keyword (other than just the text line)

My current ps1 script:-

$Content = Get-Content E:\*.txt
$Content | Foreach {
                    if ($_ -like "CurrentEdition=*,*") {Write-Output $_}
                    }


Please help.
Avatar of oBdA
oBdA

Try this:
Get-ChildItem E:\*.txt -Recurse | ForEach-Object {If (Select-String -Path $_.FullName -Pattern 'CurrentEdition=.*,.*') {$_}} | Select-Object DirectoryName,
Name

Open in new window

Avatar of Brian Smith

ASKER

Hi oBdA,

Thank you for your suggestion.

Your ps1 commandline given did list down all the *.txt filename + the respective directory (including sub-directories).

So now, how can I combined both of my script and your's together, so that the end result will show me both (the entire line of file content that met the search criteria together with the respective filename + the path location) info simultaneously?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect! Thank you so much for making my day  :)