none
find string in bunch of file and return path of file where it is found RRS feed

  • Question

  • Hi,

    This is our situation: we have a lot of file in different folders. The root of the folder structure is like:

    c:\folder1
    c:\folder2
    c:\folder3

    Whithin these folders there are alot of subfolders and files (also deeper in the tree).

    We need to find a particular string in all the files and then return the full path of the file where the string is found.
    This is the command that I use to perform this and I receive the result that I want

    Get-ChildItem c:\folder* -Recurse | Select-String -Pattern $stringToSearch | select-object Path | Out-File c:\temp\res.txt

    This does work but takes a lot of memory usage. Is there a better way to do this?

    Thx!
    Robby

    Friday, December 9, 2016 3:18 PM

Answers

  • This might be faster:

    Get-ChildItem c:\folder* -Recurse -Directory | 
    	ForEach-Object{
    		Select-String -Path "$_\*" -Pattern $stringToSearch 
    	} | 
    	select-object Path | Out-File c:\temp\res.txt


    \_(ツ)_/


    Friday, December 9, 2016 5:20 PM

All replies