chance
chance

Reputation: 6487

How to delete files containing certain string using batch file in Windows?

My Panasonic camera uses its stupid PHOTOfunSTUDIO to import photos. It creates folders by the name of the date when photos are taken, and imports photos into those folders respectively. So far so good. But If I import again before removing all old pictures from camera, the old ones will be imported again by adding a name suffix (002),(003),..., no mater how I change the settings of that software.

My question: how to remove all the files that having name suffixes from those folders?

For example, this is one folder:

D:\Photos\2011\2011-12-01>dir  /b
20111201_184550(002).cont
20111201_184550(002).iis
20111201_184550(002).m2ts
20111201_184550(002).tmb
20111201_184550.cont
20111201_184550.iis
20111201_184550.m2ts
20111201_184550.tmb

Upvotes: 12

Views: 26498

Answers (3)

Iman
Iman

Reputation: 18906

you can easily use wildcard asterix (*) to search like any search utility

-- search current folder when directory is not specified

del Search_Service_Application_1_*.trn

-- specifying specific folder working even if you are in another drive

del d:\test\*copy*.txt

Upvotes: 2

spearson
spearson

Reputation: 1016

del *"("*")".* /s 

The " " around the ( mean that it is a character instead of being part of the delete command.
/s - includes all subfolders

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/del.mspx?mfr=true

http://msdn.microsoft.com/en-us/library/ms690414%28v=vs.85%29.aspx

Upvotes: 6

chance
chance

Reputation: 6487

OK, maybe I was stupid. It does not need any batch:

del /s *(00?).*

Upvotes: 13

Related Questions