Rename multiple files with different extensions to .backup

Welcome Forums General PowerShell Q&A Rename multiple files with different extensions to .backup

This topic contains 5 replies, has 4 voices, and was last updated by

 
Participant
6 months, 2 weeks ago.

  • Author
    Posts
  • #101828

    Participant
    Points: 0
    Rank: Member

    Hello –
    I am trying to create a script that will be contained in file distributions that copies the files contained and renames the existing files at the endpoint to *.backup – The files do not have uniform extensions, or names.

  • #101831

    Participant
    Points: 342
    Helping Hand
    Rank: Contributor

    Have you tried anything? Maybe a search for Powershell Rename File. We're happy to help if you're having issues, but this isn't a script writing service.

    • #101839

      Participant
      Points: 0
      Rank: Member

      So far I have tried a couple dozen versions. Apologies for not having posted them.
      Im new to powershell, so im struggling to understand how each of the objects is being processed and what I can use as a wildcard and what I cannot.
      This is what I have been trying to get working
      get-childitem -path $path | rename-item -newname (*.*, *.backup)
      I have tried a large number of different methods to change the wild cards including *_.name, "name.$_", $_.

      Im not needing a script written, Just need to understand how to create the correct wild card after -newname to leave the file name, and change only the extension.

  • #101840
    Jon

    Participant
    Points: 37
    Rank: Member

    https://stackoverflow.com/questions/12120326/how-do-i-change-the-extension-of-many-files-in-a-directory

    get-childitem -path $path | rename-item -newname { [io.path]::ChangeExtension($_.name, ".backup") }

  • #101869

    Participant
    Points: 0
    Rank: Member

    End result
    Files = Get-ChildItem -path $path -Recurse | Select-Object -ExpandProperty Name
    Foreach ($File in $Files)
    {
    IF ($File -like '*.*')
    {
    Rename-Item -Path $path\$File -NewName "$file.backup" -Force
    }
    else
    {
    $false
    }
    }

  • #101876

    Participant
    Points: 10
    Rank: Member
    Get-ChildItem -Path \\path\ -Recurse -File | 
    Rename-Item -NewName {$_.Name + '.backup'} -WhatIf
    

The topic ‘Rename multiple files with different extensions to .backup’ is closed to new replies.