Batch Renaming on a file share

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.


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

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

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

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