PC Review
Forums
Newsgroups
Microsoft Access
Microsoft Access VBA Modules
application.filesearch
Forums
Newsgroups
Microsoft Access
Microsoft Access VBA Modules
application.filesearch
![]() |
application.filesearch |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
"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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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", "|") |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

