PDA

View Full Version : Help Please


aelphaeis
01-23-2004, 07:21 AM
How do you delete a file in visual basic ?

I mean say if you have a form with one button on it called Command1 ok the code i would assume would be

Command1_Click()

Delete "C:/Test.txt"

End If


Obviously that doesnt work but could i please have the code for it.

quatu
01-29-2004, 08:01 AM
You can use the FileSystemObject to delete a file:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vaobjfilesystemobject.asp

Command1_Click()

Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile "C:\Test.txt"

End If

quatu
01-29-2004, 08:03 AM
Or you can just use the the Kill method:

Command1_Click()

Kill "C:\Test.txt"

End If