Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell find and replace not recursing through sub-directories
    primarykey
    data
    text
    <p>I would like to recurse through all subfolders of a given folder, and for all files of a given extension (optionally wildcard), search and replace some piece of text. </p> <p>There's a similar previous question <a href="https://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir">here</a>, and I'm trying to get a modified version of the top answer working for my purpose. It uses Powershell for the find and replace. However, my modified version below is not recursing. I don't remember where I found the <code>recurse</code> part of the first line, so maybe I'm using that incorrectly. </p> <pre><code>Get-ChildItem *.* -exclude *.ps1* -recurse | Foreach-Object { $c = ($_ | Get-Content) $c = $c -replace 'foo','bar' [IO.File]::WriteAllText($_.FullName, ($c -join "`r`n")) } </code></pre> <p>I am running the code from the Powershell command line as a PS batch file, <code>.ps1</code>, hence the exclusion of that extension. </p> <p>This works fine if I run it directly in a folder that has some files I want searched, but if I run it from a parent of that folder, the searching/ recursion of subfolders does not happen. It doesn't even try to, which I can tell from the fact that the command finishes running instantaneously. If I run it in my first subfolder, which has about 50 text files, there's a couple seconds delay before it finishes, indicating to me it's actually searching those files. </p> <p>I've also tried this with the exclude portion removed and the behaviour is the same. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload