Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:04:54+00:00 2026-05-30T19:04:54+00:00

Recursive renaming files using PS is trivial (variation on example from Mike Ormond’s blog

  • 0

Recursive renaming files using PS is trivial (variation on example from Mike Ormond’s blog):

dir *_t*.gif -recurse 
    | foreach { move-item -literal $_ $_.Name.Replace("_thumb[1]", "")}

I’m trying to recursively rename a folder structure.

The use case is I’d like to be able to rename a whole VS.NET Solution (e.g. from Foo.Bar to Bar.Foo). To do this there are several steps:

  1. Rename folders (e.g. \Foo.Bar\Foo.Bar.Model => \Bar.Foo\Bar.Foo.Model)
  2. Rename files (e.g. Foo.Bar.Model.csproj => Bar.Foo.Model.csproj)
  3. Find and Replace within files to correct for namespace changes (e.g. ‘namespace Foo.Bar’ => ‘namespace Bar.Foo’)

I’m currently working the first step in this process.

I found this posting, which talks about the challenges, and claims a solution but doesn’t talk about what that solution is.

I keep running into the recursion wall. If I let PS deal with the recursion using a flag, the parent folder gets renamed before the children, and the script throws an error. If I try to implement the recursion myself, my head get’s all achy and things go horribly wrong – for the life of me I cannot get things to start their renames at the tail of the recursion tree.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:04:55+00:00Added an answer on May 30, 2026 at 7:04 pm

    Here’s the solution rbellamy ended up with:

    Get-ChildItem $Path -Recurse | %{$_.FullName} |
    Sort-Object -Property Length -Descending |
    % {
        Write-Host $_
        $Item = Get-Item $_
        $PathRoot = $Item.FullName | Split-Path
        $OldName = $Item.FullName | Split-Path -Leaf
        $NewName = $OldName -replace $OldText, $NewText
        $NewPath = $PathRoot | Join-Path -ChildPath $NewName
        if (!$Item.PSIsContainer -and $Extension -contains $Item.Extension) {
            (Get-Content $Item) | % {
                #Write-Host $_
                $_ -replace $OldText, $NewText
            } | Set-Content $Item
        }
        if ($OldName.Contains($OldText)) {
            Rename-Item -Path $Item.FullName -NewName $NewPath
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a recursive glob to find and copy files from a drive to
I'm using recursive jQuery AJAX to callback values from the server every second. However,
I often use this recursive 'visitor' in F# let rec visitor dir filter= seq
So I'm using recursive blocks. I understand that for a block to be recursive
The question is related to the answer about renaming files recursively. The code, changed
This recursive definition of a macro does what it should (sum integers from 1
When using PowerShell to extract information from TFS, I find that I can get
I'm doing a recursive copy of files and like xcopy /D I only want
I am using a recursive function based around for(.. in ..) and hasOwnProperty to
I have a recursive function from a C book as follows: void print(int a[],

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.