Author Posts

March 11, 2016 at 11:18 am

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.

Example

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.

March 11, 2016 at 11:40 am

Hi

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 http://stackoverflow.com/questions/12503871/removing-path-and-extension-from-filename-in-powershell

March 11, 2016 at 12:16 pm

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

March 11, 2016 at 1:20 pm

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

March 11, 2016 at 3:41 pm

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