Where am I going wrong?!

Welcome Forums General PowerShell Q&A Where am I going wrong?!

This topic contains 2 replies, has 3 voices, and was last updated by

1 year, 9 months ago.

  • Author
  • #70594

    Points: 0
    Rank: Member

    Hello all,
    Fairly new to Powershell so please be kind.

    I am trying to rename all files in a folder that contains open and closing brackets with a word in the middle.
    I have over 1000 files in a folder all with different words in brackets. but they need to be replaced.

    This is what I have so far:

    get-childitem *.zip | foreach { rename-item $_ $_.Name.Replace(" (*)""", "") }

    Ive put an asterix in open and closed brackets in hope that'll be the wild card and get rid of anything in brackets.

  • #70598

    Points: 22
    Rank: Member

    Moving to correct forum.

    • #70606

      Points: 643
      Helping Hand
      Rank: Major Contributor

      Replace works with regular expressions.
      Try it this way:

      Get-ChildItem -Path '*.zip' | ForEach-Object {
          Rename-Item -Path $_.FullName -NewName (($_.BaseName -replace '\(.+\)') + $_.Extension )

The topic ‘Where am I going wrong?!’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort