application.filesearch

B

brian

I use the following vb function to delete .ord files in
our 5 gig directory. Now I need to delete about 15 other
extentions out of the directory. Is there a way to group
all the extensions together? I can only get it done by
creating the code for each extension.

Thanks

Function SimpleSearch()

' Perform simple search using the FileSearch object.
Dim varFile As Variant
With Application.FileSearch
.NewSearch
.FileName = "*.ord"
.LookIn = "g:\Orders\"
.Execute
.SearchSubFolders = True
For Each varItem In .FoundFiles
Debug.Print varItem
Kill (varItem)
Next varItem
End With
MsgBox "end"
End Function
 
T

TC

brian said:
I use the following vb function to delete .ord files in
our 5 gig directory. Now I need to delete about 15 other
extentions out of the directory. Is there a way to group
all the extensions together? I can only get it done by
creating the code for each extension.

Why? Just use another procedure:

Function SimpleSearch()
deletefiles "ord"
deletefiles "abc"
deletefiles "def"
etc.
End Function
....
Private Sub DeleteFiles (pExtension as string)
(put your delete code here, using pEntension instead of "*.ord")
End Sub

HTH,
TC
 
H

HSalim

Brian,
I am replying to this after much hesitation. I am assuming you are not a
malicious user.

That is some really dangerous code and I am concerned that it is in a public
newsgroup.

Why would you call the function SimpleSearch when it deletes files?
That is a great way to harm yourself at a later date when you try using the
function
without realizing that there is a bomb in it.

Anyway, since you ask,
You could wrap your code in a loop like this:

Function SimpleSearch(FileTypes As String. Delimter as string)
Dim Extensions() As String, i As Integer
Extensions = Split(FileTypes, Delimiter)
For i = 0 To UBound(Extensions)

' your code
Next i

and call it like this
SimpleSearch (".txt|.ord", "|")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top