<p>I would like to rename files and folders recursively by applying a string replacement operation.</p>

<p>E.g. The word "shark" in files and folders should be replaced by the word "orca".</p>

<p><code>C:\Program Files\Shark Tools\Wire Shark\Sharky 10\Shark.exe</code> </p>

<p>should be moved to:</p>

<p><code>C:\Program Files\Orca Tools\Wire Orca\Orcay 10\Orca.exe</code></p>

<p>The same operation should be of course applied to each child object in each folder level as well.</p>

<p>I was experimenting with some of the members of the <code>System.IO.FileInfo</code> and <code>System.IO.DirectoryInfo</code> classes but didn't find an easy way to do it.</p>

<pre><code>fi.MoveTo(fi.FullName.Replace("shark", "orca"));
</code></pre>

<p>Doesn't do the trick.</p>

<p>I was hoping there is some kind of "genius" way to perform this kind of operation.
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>

So you would use recursion. Here is a powershell example that should be easy to convert to C#:
```
```
function Move-Stuff($folder)
{
    foreach($sub in [System.IO.Directory]::GetDirectories($folder))
      {
        Move-Stuff $sub
    }
    $new = $folder.Replace("Shark", "Orca")
    if(!(Test-Path($new)))
    {
        new-item -path $new -type directory
    }
    foreach($file in [System.IO.Directory]::GetFiles($folder))
    {
        $new = $file.Replace("Shark", "Orca")
        move-item $file $new
    }
}

Move-Stuff "C:\Temp\Test"
```
```