Sunday, 25 August 2013

How to create batch file that delete files by words at the end of file name (using a list of words)?

How to create batch file that delete files by words at the end of file
name (using a list of words)?

I have a directory with thousands of html files scattered across several
subdirectories. I need to delete all files matching any one of many
criteria. All criteria are similar by kind. The file names are like:
MM-DD_hh-mm-ss__www.host.com.html
So, all files that are ending in certain hostnames must be deleted. There
are about 20 hostnames for now. (But that number will increase to about
100.) I store a list in txt file and prefer to do so.
__first.site.com.html
__www.secondsite.com_.html
__site.com_numberthree.html
The thing is, some "good" files contain "bad" hostnames but not at end of
file name.
__www.onesite.com_.html (bad)
__www.onesite.com_prices.html (good)
Can I create a bach file to safely scan all subdirectories and remove
unnecessary files using the list? OS is Windows 7. I want to set up Task
Scheduler to run such butch each night. But I'm not familiar with
commands. Please help.
P.S. In fact, some "bad" files have linked folders _files. I expect they
will be deleted automatically like it happens when I manually delete main
html file.

No comments:

Post a Comment