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

二次信任 提交于 2019-12-22 04:16:18

问题


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

回答1:


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

del /s *(00?).*



回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/8513510/how-to-delete-files-containing-certain-string-using-batch-file-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!