renaming files

Welcome Forums General PowerShell Q&A renaming files

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

1 year, 9 months ago.

  • Author
  • #70522

    Points: 0
    Rank: Member

    Hi guys,

    I have to rename over 2000 files.

    I get the files by using:

    $List = Get-ChildItem -Filter *2015*

    Then i only want the first 8 characters and i do:

    $List = ForEach-Object {$a.Substring(0,13)}

    The i add some text

    $b = $a | Foreach-Object{ $_ + '_bw' }
    $c = $b | Foreach-Object{ $_ + '.pdf' }

    But i only receive the last file in the c$ could somebody help me to change all the filenames put it in a string and then rename the files on fileserver

  • #70525

    Points: 643
    Helping Hand
    Rank: Major Contributor

    You should start with learning the basics of Powershell. Here are some good sources: Beginner Sites and Tutorials
    Your task could be accomplished like this:

    Get-ChildItem -Path C:\sample\* -Filter *2015* | 
        ForEach-Object -Process {
            $newName = $($_.BaseName.substring(0,8)) + '_bw' + $($_.Extension)
            Rename-Item -Path $_.FullName -NewName $newName

    Of course you should change the starting path to your needs

    • #70528

      Points: 0
      Rank: Member


      Thank you very much, i rather new to powershell that's correct. Will follow your advice. thanks!

The topic ‘renaming files’ is closed to new replies.

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