PC Review


Reply
Thread Tools Rate Thread

application.filesearch

 
 
brian
Guest
Posts: n/a
 
      1st Aug 2003
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
 
 
 
 
TC
Guest
Posts: n/a
 
      2nd Aug 2003

"brian" <(E-Mail Removed)> wrote in message
news:035301c3585c$77dca410$(E-Mail Removed)...
> 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
 
HSalim
Guest
Posts: n/a
 
      2nd Aug 2003
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - Application.Filesearch Nelson79 Microsoft Excel Discussion 0 12th Jun 2011 11:58 AM
Application.FileSearch Cleberton(Brazilian) Microsoft Excel Misc 2 26th Oct 2009 02:21 PM
application.filesearch dstiefe Microsoft Excel Programming 3 13th Aug 2009 11:30 PM
Application.Filesearch EA Microsoft Excel Programming 3 17th Aug 2006 11:07 AM
Application.FileSearch Bernie Microsoft Access Form Coding 1 21st Sep 2004 02:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:01 PM.