Search a folder/files for string of text

Search a folder/files for string of text 2.1


Ian

Administrator
Joined
Oct 27, 2013
Messages
1,537
Reaction score
520
Ian submitted a new article:

Search a folder/files for string of text - Use PowerShell to search a folder for a particular string of text in your files

I was looking for a Windows application that would allow me to search some files in the same folder for a particular string of text, but many of the apps to do this were fairly expensive. So, I made use of a few lines of PowerShell code to do this for free!

This script will prompt you for the folder to search (it will search ALL files in this folder and any sub-directories), then it will ask you for the string of text to search for.

The filename and line of text are then listed, so you can...
Read more about this article...
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
2,937
Reaction score
910
Nice one Ian :D

Love your ASCii art too !


Here's a suggestion for a modification though for the lazy ones who can't be bothered typing their File Path, or like me have fingers who joined a Union and at any moment decide they want to Strike and as a result the typed path gets a little jumbled :rolleyes:

OK I confess, in my rush to try your script out I couldn't recall the full file path I wanted to test it on :eek: So I wrote a quick function as it was faster for me to do that than remember the file path *lol*

Code:
Function Get-SearchFolder {
  $object = New-Object -comObject Shell.Application
  $folder = $object.BrowseForFolder(0, "Which folder do you wish to search (includes subfolders)", 0)
  if ($folder -ne $null) {
    $searchfolder = $folder.self.Path.substring(0,$folder.self.path.length)
    if ($folder.self.path.substring($folder.self.path.length - 1, 1) -ne "\") {
      $searchfolder = $folder.self.Path.substring(0,$folder.self.path.length) + "\"
    }
  }
  Set-Location $searchfolder
}
Write-Host 'Which folder do you wish to search (includes subfolders)'
$searchfolder = Get-SearchFolder
$textstring = Read-Host -Prompt 'Please enter the string to search for'
Get-ChildItem $searchfolder -Filter *.* -Recurse | Select-String $textstring
Read-Host -Prompt 'Search Complete. Press ENTER to exit...'
 
Last edited:
  • Like
Reactions: Ian
Ad

Advertisements

Joined
Nov 19, 2013
Messages
4,310
Reaction score
842
This is a little over my head. It seems like a good thing.
You can actually search for text using the built in search facility, if you plunge into the advanced index options.
I have never tried it!!!
 
  • Like
Reactions: Ian

Ian

Administrator
Joined
Oct 27, 2013
Messages
1,537
Reaction score
520
Here's a suggestion for a modification though for the lazy ones who can't be bothered typing their File Path, or like me have fingers who joined a Union and at any moment decide they want to Strike and as a result the typed path gets a little jumbled :rolleyes:
Great idea - this makes things a lot easier!

I'm updating the article now :).
 

Regedit32

Moderator
Joined
Mar 4, 2016
Messages
2,937
Reaction score
910
Don't forget to add your username to your file header :) on the version 2 download.
 
  • Like
Reactions: Ian
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top