0

I used Office File Converter (OFC) to convert my old Office documents to the newer format with a an X (docx, xlsx, pptx). OFC did not provide an option to delete converted documents. Now, I need to traverse through my documents folder to find duplicate file names but with a different extension. For example, my Word document with a name of superuser.doc will also have a converted copy called superuser.docx.

Sun
  • 6,318

1 Answers1

1

This is really very easy in PowerShell. I am providing you with a script that searches the current folder and its subfolders for files with .docx, .xlsx and .pptx extensions, then deletes all files with the same name but with .doc, .xls and .ppt extensions.

The responsibility of navigating to the right folder before running this script lies with you.

Get-ChildItem *.docx,*.xlsx,*.pptx -Recurse | ForEach-Object {
  $filePath = $_.FullName
  $filePath = $filePath.TrimEnd("x")
  Remove-Item $filePath
}

I deliberately used multiple lines and full readable names to make the script understandable. (I could make it a one-liner.) But copying and pasting it whole into PowerShell is supported! :)

Seth
  • 9,165
  • $a wasn't really clear but otherwise a really nice approach! – Seth Apr 10 '17 at 07:44
  • Damn it, knew I forgot something. That comment was just there in case you were wondering about the edit. – Seth Apr 10 '17 at 07:47
  • 1
    @Seth Nah. It was obviously a good edit. If I use full command names, I might as well give meaningful names to variables too. –  Apr 10 '17 at 07:48