File rename output

Welcome Forums General PowerShell Q&A File rename output

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

6 months, 2 weeks ago.

  • Author
  • #113585

    Points: 0
    Rank: Member

    Hi, I am running the script below to rename files and it is working fine. what I would like to add is something that would either show in PS or export in a CSV file all the changes made.
    For example, if I am renaming t+est.pdf to test.pdf, the output I need something that says
    old name t+est.pdf new name test.pdf.
    Set-Location -Path "C:\Temp\File rename"
    Get-ChildItem -Recurse -Include *.pdf | Rename-Item -NewName {$_.Name.Replace("+","_")}
    Thank You

  • #113603

    Points: 1,375
    Helping Hand
    Rank: Community Hero

    You could start with something like this:

    Get-ChildItem -Path "C:\Temp\File rename" -Recurse -Include *.pdf | 
                NameBefore = $_.Name
                NameAfter = $_.Name.Replace("+","_")
            Rename-Item -Path $_.FullName -NewName {$_.Name.Replace("+","_")}

    .... untested!!
    Of course you could pipe the output to whatever further cmdlet or file you want.

  • #113614

    Points: 1,991
    Helping Hand
    Rank: Community Hero

    You can use Write-Output to print it in the console or if in a CSV you can build a PSCustomObject with Oldname and Newname as headers and export it to a CSV. Yourself can do it, there are lot of example in the web on PSCustomObjects. Once you face any issues using CustomObjects, update it here, we will guide you.

    here is a link for understanding PScustomObjects :

    If you are very new to PowerShell, I would suggest you to take some time in learning and understanding the language else you will get frustrated by doing things not right.

    A good places to start

  • #113626

    Points: 968
    Helping Hand
    Rank: Major Contributor

    rename-item has -verbose and -passthru options. But passthru only returns in the new file.

The topic ‘File rename output’ is closed to new replies.

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