[RESOLVED] How to delete multiple files
I am trying to delete multiple files (.reg files) by using following code.
Quote:
My.Computer.FileSystem.DeleteFile(Environ("%systemdrive%") & "\*.reg")
But its is generating an exception: Argument Exception was Unhandled.
Illegal Characters in path.
Any ideas what is going wrong.
Re: How to delete multiple files
Try this:
Code:
Try
Dim regFiles() As String = System.IO.Directory.GetFiles(System.IO.Path.GetPathRoot(Environment.SystemDirectory), "*.reg")
For Each regFile As String In regFiles
System.IO.File.Delete(regFile)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try