I know how you love to hear from me, but I have a questsion (for the nth time), how do you use a delete command to delete or creat a file in vb?
Printable View
I know how you love to hear from me, but I have a questsion (for the nth time), how do you use a delete command to delete or creat a file in vb?
Here's the KIll'using fso kill a file
Code:'before killing check for existence to avoid error on kill
'
Dim sFile$
sFile = "Path & Name Of Your File.ext"
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(sFile$) = True Then
Kill sFile
Else
MsgBox "Sorry, the specified file does not exist!"
End If
Set FSO = Nothing
Use Kill to delete a file
Code:Kill "MyFile.txt"
To create a file. Mainly a text file.
Or you could open it for Append which will not overwrite the file, but add to the end of it.Code:Open "C:\myfile.txt" For Output As #1 'Create/Overwrite if existing
Print #1, "You have just created a file called myfile.txt located in C:\ directory." 'write text
Close #1 'Close the file
Code:Open "C:\myfile.txt" For Append As #1
Print #1, "You wrote some more text after the 'You have just created a file called...'"
Close #1