syseng007
asked on
Query a Word within Lines of Files Recursively?
Scenario - We have outdated files in our file shares of names of our old management team. We need to replace those files but since there are hundred of all types of files (ie, .doc, .html, .pdf)- Is there a way to query within files of Name: Mr Ex President recursively and dump it into an output file? Please advise! Thanks!
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
@ marahman3001 - Can you please add a line so I can export the results to a csv file? Thank you.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
$search = read-host "enter search word"
$files = Get-ChildItem c:\support\shutdown\*.*
foreach ($file in $files)
{
$contents = Get-Content $file | Out-String
if($contents.contains($sea rch))
{
Add-content -path c:\temp\result.csv -value "Found $search in $file"
}
}
$files = Get-ChildItem c:\support\shutdown\*.*
foreach ($file in $files)
{
$contents = Get-Content $file | Out-String
if($contents.contains($sea
{
Add-content -path c:\temp\result.csv -value "Found $search in $file"
}
}
ASKER
@ThomasMcA2 - Does Locate32 find text or data within files? or just names of files?
ASKER
@marahman3001 - Thank you for the response but the script does not query the files recurisvely...Also how can Iresume when there is a permission denied error? Thanks again!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
To do the same thing via a script would require a decent amount of work I'd imagine. You'd need to open each file in each directory. Opening the file in its appropriate application wouldn't be too much of a problem but searching for key words within the file will require you to identify the application and use automation to perform the search. I could be wrong though.
OM Gang