Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 239
chance Avatar asked Dec 15 '11 00:12

chance


3 Answers

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

del /s *(00?).*
like image 67
chance Avatar answered Nov 14 '22 05:11

chance


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

like image 41
spearson Avatar answered Nov 14 '22 05:11

spearson


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
like image 2
Iman Avatar answered Nov 14 '22 05:11

Iman