Rename files and move to a folder

Welcome Forums General PowerShell Q&A Rename files and move to a folder

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

 
Participant
1 year, 1 month ago.

  • Author
    Posts
  • #78748

    Participant
    Points: 0
    Rank: Member

    Hello i'm trying for a while to rename pdf files that are like letters in the beginning and in the end date: example_if_name_04.09.2017.pdf. I want to rename all of them to date 04_09_2017.pdf or 04092017.pdf.

    I did something like this:

    $z = Get-ChildItem c:\fso -Filter *.pdf -Recurse | % { $_.FullName }
    $files = $a -replace '[^0-9]', "

    foreach($i in $files)
    {
    $d = $i+".pdf"
    Rename-Item $z $i -WhatIf
    }

  • #78755

    Participant
    Points: 10
    Published
    Rank: Member
    # Replace dot with underscore and keep extension
    Get-ChildItem C:\fso -Filter *.pdf | Rename-Item -NewName {
        ($_.BaseName -replace '\.','_') + $_.Extension}
    
  • #78760

    Participant
    Points: 0
    Rank: Member

    Thanks, done it with this:

    Get-ChildItem C:\fso -Filter *.pdf | Rename-Item -NewName {
        ($_.BaseName -replace '[^0-9]', '') + $_.Extension}
  • #78793

    Inactive
    Points: 0
    Rank: Member

    You can try the below command:

    In DOS /CMD

    move file.ext \\server\folder\newfile.ext

    move /?

    In PowerSHell:

    Move-Item file.ext \\server\folder\newfile.ext

    Move-Item -?

    In VBScript:

    fso.MoveFile "file.ext:, "\\server\folder\newfile.ext"

    For more information, please checkout the below articles:

    http://technet.microsoft.com/en-us/library/ee176940.aspx

    http://technet.microsoft.com/en-us/library/ee176910.aspx

  • #80635

    Participant
    Points: 0
    Rank: Member

    I use, Batch Rename Files Tool. You can easily found hier BatchRenameFiles.org that allows you to quickly rename all the files in a specified directory.

The topic ‘Rename files and move to a folder’ is closed to new replies.