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.
Asked
Active
Viewed 3,739 times
1 Answers
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,393