I found this example in MSDN. Is this only for text files or can I also use this to delete image files?????
I noticed that in this example it creates new text file then copy content of older text file then deletes the new one. Why????
The following example deletes a file from the specified path.
[Visual Basic]
Imports System
Imports System.IO
Imports System.Text
Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\temp\MyTest.txt"
Try
Dim sw As StreamWriter = File.CreateText(path)
sw.Close()
Dim path2 As String = path + "temp"
' Ensure that the target does not exist.
File.Delete(path2)
' Copy the file.
File.Copy(path, path2)
Console.WriteLine("{0} was copied to {1}.", path, path2)
' Delete the newly created file.
File.Delete(path2)
Console.WriteLine("{0} was successfully deleted.", path2)
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
|