Batch Renaming on a file share

Tagged: 

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of random commandline random commandline 6 months, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #36431
    Profile photo of Tim Jurich
    Tim Jurich
    Participant

    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.

    #36432

    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

    #36437
    Profile photo of random commandline
    random commandline
    Participant
    # Replace '..' from names (remove one dot)
    Get-ChildItem -Recurse -Path .\my\path | Rename-Item -NewName {$_.name -replace '\.\.','.'} -WhatIf
    
    #36446
    Profile photo of Tim Jurich
    Tim Jurich
    Participant

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

    #36447
    Profile photo of random commandline
    random commandline
    Participant

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

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.