Batch Renaming on a file share

This topic contains 4 replies, has 3 voices, and was last updated by  random commandline 2 years, 4 months ago.

  • Author
  • #36431

    Tim Jurich

    We currently have a CIFS share hosted from a SAN device and are planning to move toward a case management system. The issue I'm having is a lot of the various files in our file share end with a trailing dot (.) and fail to upload.

    I've been trying to get a script working that would keep file names the same but batch remove any trailing dots. I've been able to do this with various special characters using powershell.

    We also have many sub folders that have a dot (.) in the middle of the folder name and would need to leave these alone.


    Original File name: 20151101 Luis K. Abrishamian M.D..pdf

    New file name: 20151101 Luis K. Abrishamian M.D.pdf

    I used this one to remove all & from file names

    Get-ChildItem -recurse -name | ForEach-Object { Move-Item $_ $_.replace("&", "and") }

    I tried these but it failed to do what i needed

    Get-ChildItem -recurse -name | ForEach-Object { If($_.Substring($_.Length-1) -eq ".") { Move-Item $_ $_.Substring(0,$_.Length-1) } }

    Get-ChildItem -recurse -name | ForEach-Object { Move-Item $_ ([regex]::Replace($_, "\.$" , "")) }

    Get-ChildItem -recurse -name | ForEach-Object { Move-Item $_ $_.replace("*.", "") }

    This would take care of thousands of files i have to rename and would save me weeks of agonizing pain if i could get some help with this.

  • #36432


    How about if you use foreach file something like | select basename and then if the last character is dot remove it?

    Lint that I found that could be helpful

  • #36437

    random commandline
    # Replace '..' from names (remove one dot)
    Get-ChildItem -Recurse -Path .\my\path | Rename-Item -NewName {$ -replace '\.\.','.'} -WhatIf
  • #36446

    Tim Jurich

    random command line you are amazing! you saved me weeks of painfully renaming thousands of files manually.

  • #36447

    random commandline

    Excellent! Tim, glad I could help. Just curious, what type of case management system are you moving towards?

You must be logged in to reply to this topic.