Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting files based on internal text value 1

Status
Not open for further replies.

volant

Programmer
Feb 4, 2003
9
US
I need to delete files from a directory.
I need to search within the files for a specific text value, and then delete the file if it contains the text I'm looking for.
i.e.

delete all files containing 'xbx'
 
What have you so far ?
You can play with the FileSystemObject and the InStr function.

Hope This Help
PH.
 
I'm nowhere at this point. This is not an area i'm familier with.
 
Try something like this:
Code:
Set fso=CreateObject("Scripting.FileSystemObject")
Set f=fso.GetFolder("C:\Path\to\folder")
Set fc=f.Files
For Each fl in fc
  If Right(LCase(fl.Path),3)="txt" Then
    Set ts=fl.OpenAsTextStream(1)
    found=False
    Do While Not ts.AtEndOfStream
      If InStr(1,ts.ReadLine,"Searched String",1)>0 Then
        Found=True
        Exit Do
      End If
    Loop
    ts.Close
    If Found Then WScript.Echo fl.Path: fl.Delete
  End If
Next

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top