Link to home
Create AccountLog in
Avatar of syseng007
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!
Avatar of omgang
omgang
Flag of United States of America image

What you're wanting to do is exactly the type of thing a desktop search tool is designed for.  You may want to download a trial of a DTS (I've used and am happy with Copernic) and try it out.  After installing the DTS you configure it to index volumes/shares on your network.  Give it a day or so to construct a complete index and then perform key word searches.  It will find matches in most file types.

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
SOLUTION
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of syseng007
syseng007

ASKER

@ marahman3001 - Can you please add a line so I can export the results to a csv file? Thank you.
SOLUTION
Link to home
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($search))
 {
    Add-content -path c:\temp\result.csv -value "Found $search in $file"
  }
}
@ThomasMcA2 - Does Locate32 find text or data within files? or just names of files?
@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
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.