locked
Powershell script to remove unwanted file extension RRS feed

  • Question

  • Thanks to a Backup program that will remain nameless(although when you see the extension, you will know who it is) I have 1000's of files on an external disk that have a .IAB attached to the end of a file (ie: reporting.xls.iab for example). These files are scattered throughout the disk in about 250 directories and subdir as well. I've found that if I rename the file by deleting the extra extension the file is in tact and useable. Mainly any file with .exe, .doc, .xls, .ppt are the ones I'm most interested in but I would be happy to have all the files be renamed without the .IAB.

    Is there a script out there that can handle this? I know you Scripting Guys can work magic and I'm hoping you can do your thing here as well.

     

    Thanks Pogo7720

    Tuesday, March 23, 2010 12:58 PM

Answers

  •  

    This should work.

    gci <dir path \*.iab> |% {rename-item $_.fullname -newname $_.basename -whatif}

     

    Try it with the -whatif first.  If the results look like what you want, remove the -whatif and re-run.

    • Marked as answer by IamMred Tuesday, March 23, 2010 7:09 PM
    Tuesday, March 23, 2010 1:16 PM

All replies

  •  

    This should work.

    gci <dir path \*.iab> |% {rename-item $_.fullname -newname $_.basename -whatif}

     

    Try it with the -whatif first.  If the results look like what you want, remove the -whatif and re-run.

    • Marked as answer by IamMred Tuesday, March 23, 2010 7:09 PM
    Tuesday, March 23, 2010 1:16 PM
  • Thank you for the suggestion. I will be able to try that out tonight. So just 1 line to do this.

    I love Powershell

    Tuesday, March 23, 2010 6:47 PM
  • I have another issue, like this, the extension is a problem, but does not have .ext.ext, files have .exe[textlinehere] and I need to rename by stripping off the [textlinehere] and renaming to just .ext

    can this be done?

    thanks in advance


    SCC

    Friday, April 26, 2019 7:12 PM
  • Please do not add additional questions to other peoples threads. Create a new one for yourself and place a link to this one if needed.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, April 26, 2019 7:31 PM
  • Or more simply:

    ls *.iab  | rename-item -newname { $_.basename } -whatif
    ls *.exe* | rename-item -newname { $_ -replace '\.exe.*$','.exe' } -whatif

    • Edited by JS2010 Monday, April 29, 2019 6:46 PM
    Monday, April 29, 2019 2:30 PM