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!

Delete Multiple Files

Status
Not open for further replies.

kitackers

MIS
Apr 16, 2004
33
GB
I hope some one can help..

I was wondering if it is possible to search a file and delete any files that do not start with the string branch_inbound using vba



 
You could load all the file names into an array, loop though it, open each file search for your string then delete it if you didn’t find it. Google "vba file list"

All I want is the chance to prove money won't make me happy.
 
Steve thanks for you help

i am kind of new to access and this has gone over my head you don't have a example of the code that i need to use do you

thanks again
 
I don't at this location, I am away from my PC that contains that specific code for a few days.

I am sure someone will post the code, it a great forum.


All I want is the chance to prove money won't make me happy.
 
thanks for you feedback

i am trying to think of another way of doing it do you know if it is possible to use the name function and the widcard together, the problem i have is the files are run at different times each night and therfore the name of the file is different each day
 
Code:
Dim FSO As New Scripting.FileSystemObject
Dim fil As Scripting.File

With FSO
   For Each fil in .GetFolder("C:\MyFolder\").Files
      If Left$(fil.Name, 14) <> "branch_inbound" then
         fil.Delete
      End If
   Next
End With
Set FSO = Nothing
You will need a reference to Microsoft Scripting Runtime to do that.
 
golom

thanks you for all your help with my 2 problems

i have tried to input and run the above code but it is returning a error user define type not defined and seleting the top row ("Dim FSO As New Scripting.FileSystemObject")
 
Or, simply use late binding, ie replace this:
Dim FSO As New Scripting.FileSystemObject
Dim fil As Scripting.File
with this:
Dim FSO As Object, fil As Object
Set FSO = CreateObject("Scripting.FileSystemObject")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top