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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Kill method

Status
Not open for further replies.

Nick34

Technical User
Oct 16, 2003
50
US
Can anyone tell me why this might not work assuming that I have the path name right?

With Application.FileSearch
.NewSearch
.LookIn = sPath
.Filename = "*.rtf"
.FileType = msoFileTypeAllFiles
If .FoundFiles.Count > 0 Then
Kill (sPath & "\*.rtf")
Else
End If
End With
 
How is it not working? It will return an error if the file does not exist. If it is not killing a file that does exist, you have an error in your path. To deal with a non existent file, I usually bracket Kill with an On error Resume Next so it will continue even if the file doesn't exist. Dealing will the path error is a little trickier.
 
When I step through this, it thinks the foundfile.count is NOT > 0. However, I know that there are files there because I used the same sPath variable to output them there. This is why I am getting confused.
 
I didn't test this. Myself, I would test it locally before I unleashed someone elses Kill loop on my server, but this is how you would do it using the FSO. First set a reference to Microsoft Scripting Run time, then your solution would look like something like this:

Function KillStuff()

Dim OrdFolder As Folder
Dim strfile As File
Dim fso As New FileSystemObject


Set OrdFolder = fso.GetFolder(spath)

For Each strfile In OrdFolder.Files

If Right$(strfile.Name, 3) = "*.rtf" Then
Kill spath + "\" + strfile.Name
On Error GoTo err_h
End if
Next

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top