PC Review Forums Newsgroups Microsoft Access Microsoft Access VBA Modules application.filesearch

Reply

application.filesearch

 
Thread Tools Rate Thread
Old 01-08-2003, 08:41 PM   #1
brian
Guest
 
Posts: n/a
Default application.filesearch


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
  Reply With Quote
Old 02-08-2003, 04:26 AM   #2
TC
Guest
 
Posts: n/a
Default Re: application.filesearch


"brian" <brians@lbrspec.com> wrote in message
news:035301c3585c$77dca410$a101280a@phx.gbl...
> 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

>
> 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



  Reply With Quote
Old 02-08-2003, 07:15 AM   #3
HSalim
Guest
 
Posts: n/a
Default Re: application.filesearch

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", "|")





  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off