Solved compare and delete similar file names

May 4, 2012 at 04:07:24
Specs: Windows 64
Hi everyone,
having a folder that contains these sort of file names: file1.doc.pdf, file2.doc.pdf, file3.doc.pdf and also file1.doc, file2.doc, file3.doc, I need to eliminate all the files.doc that have the same name ending by .pdf (eg: when found "file1.doc.pdf" and "file1.doc", then delete "file1.doc"). The files could have any name, but they all end with .doc.pdf and .doc
I'm looking for a bach script for windows xp or even c++

See More: compare and delete similar file names

Report •

May 4, 2012 at 20:26:20
✔ Best Answer
Test this carefully. No allowance is made for folder or filename containing spaces.

@echo off
setlocal enabledelayedexpansion

for /f "tokens=*" %%1 in ('dir /b folder\*.pdf') do (
    set filename=%%~n1
    if exist folder\!filename! del folder\!filename!

Report •
Related Solutions

Ask Question