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!

Deleting files from a folder at the click of a button ??

Status
Not open for further replies.

dubble07

Programmer
May 8, 2002
12
CA
Anyone got an idea on this one??

I want something that will flush out my folder of all files when my user clicks a button. Does the FileSystemObject support this?

thanks in advance!!

 
Have a look at the KILL method in VBA - should do what you want Rgds
~Geoff~
 
Consider this:

BE CAREFULL ! this will without warning delete all Excel workbooks from said folder !!!!!!!


Sub deletefilename()
Dim fs As FileSearch
Dim fn As String
Dim rightsixfn As String
mypath = "C:\Production Files"
Set fs = Application.FileSearch
With fs
.LookIn = mypath
'.FileName = "*.*"
.FileType = msoFileTypeAllFiles
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
fn = .FoundFiles(i)
rightsixfn = Right(fn, 4)
If rightsixfn = ".xls" Then
Kill (fn)
End If
Next i
Else
MsgBox "There were no files found in " & mypath
End If
End With
End Sub
Thank you,
Dave Rattigan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top