0

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.

2
  • 1
    We are not here to do your work for you. Try so solve it yourself and when you get stuck on a specific problem, ask about that. I can however say that batch isn't the correct tool for the job. There are several better scripting languages for windows you can use. For example powershell, perl, python or even javascript.
    – Nifle
    Aug 25, 2013 at 11:18
  • @Nifle I apologize for disappearing. "Try so solve it yourself and when you get stuck on a specific problem, ask about that." Yes, I got it. I will try PowerShell. Thanks. Sep 7, 2013 at 10:15

1 Answer 1

0

Just a quickie to get you started:

@echo off

for /F %%p in (list.txt) do (
    echo Current pattern: %%p
    for /R "C:\" %%f in (*%%p*) do (
        echo File: %%f
    )
)

exit /B 0
6
  • This dosn't work for good files with bad host names.
    – Endoro
    Aug 26, 2013 at 5:53
  • @Endoro: why not? Aug 27, 2013 at 11:15
  • this will "delete" __www.onesite.com_prices.html
    – Endoro
    Aug 27, 2013 at 11:20
  • Ah, I misunderstood the "bad" and "good" (poor) explanation in the question. Aug 27, 2013 at 11:28
  • @Vlastimil, thank you for your time. I'm sorry for poor explanation. Sep 7, 2013 at 10:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .