renaming files

This topic contains 2 replies, has 2 voices, and was last updated by  Jaapie bakker 5 months, 1 week ago.

  • Author
    Posts
  • #70522

    Jaapie bakker
    Participant

    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

    Olaf Soyk
    Participant

    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

      Jaapie bakker
      Participant

      Olaf,

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

You must be logged in to reply to this topic.