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.

3

1 Answer 1

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! :)

3
  • $a wasn't really clear but otherwise a really nice approach!
    – Seth
    Apr 10, 2017 at 7:44
  • Damn it, knew I forgot something. That comment was just there in case you were wondering about the edit.
    – Seth
    Apr 10, 2017 at 7: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.
    – user477799
    Apr 10, 2017 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.