delete file

ADO DOT NET

Well-known member
Joined
Dec 20, 2006
Messages
156
Hi,
I want to check if there is any text file in the application path, then delete all of them.
So I use this code:
Code:
If System.IO.Directory.GetFiles(My.Application.Info.DirectoryPath, "*.txt").Length > 0 Then
 My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath + "\*.txt")
End If
But I get error:
A first chance exception of type System.ArgumentException occurred in mscorlib.dll
 
you are trying to delete the path name with \*.txt attached to the end of it there, not the actuall files, also you need to delete them 1 by 1
it can be done easily like this...
Code:
        For Each f As String In System.IO.Directory.GetFiles(My.Application.Info.DirectoryPath, "*.txt")
            My.Computer.FileSystem.DeleteFile(f)
        Next
 
Back
Top