-
Alright, I just started programming in VB, and here's what's happened so far:
I created a program that will both sort and output an HTML file with named anchors in it based on a fixed length data dump from our system.
The problem is, I did it all sequentially, and had to create a couple documents for workspace in the process. How can I delete these documents from my harddrive when the program closes?
I'm pretty sure I'll do it on a _Terminate() tag, but what goes in the middle? Some of this is secure stuff, and needs to be deleted when the processing is done. HELP!!
-
Kill yourFileName
will delete your file
-
-
First you should check if it exists else, you'll get an error.
Code:
If Dir$("This File") <> "" Then Kill "This file"
-
Whether or not it exists
Whether or not it exists is not an issue. . .I know that these files will be created every time, guaranteed.
-
ITS NOT WORKING
OK, thats not working. . .the files are still there.
Here's the line:
If Dir("c:\TXData.txt") <> "" Then Kill "c:\TXData.txt"
Whats the dealio??
TIA.
-
Make sure you close them first.
Here's my Delete File function:
Code:
Public Function DeleteFile(pstrFile As String)
On Error GoTo DeleteFileErr
If InStr(pstrFile, "*") = 0 And InStr(pstrFile, "?") = 0 Then SetAttr pstrFile, vbNormal
Kill pstrFile
DeleteFileExit:
Exit Function
DeleteFileErr:
MsgBox Err.Description, vbInformation, "Notice"
Resume DeleteFileExit
End Function
Here's the function I use to see if a file exists. It doesn't disturb the Dir queue if you are using Dir in the function that calls it:
Code:
Public Function FileExists(pstrFile As String) As Boolean
On Error GoTo FileExistsErr
FileExists = True
If GetAttr(pstrFile) And vbDirectory Then FileExists = False
FileExistsExit:
Exit Function
FileExistsErr:
If Err.Number = 53 Or Err.Number = 75 Then
FileExists = False
Else
MsgBox Err.Description, vbInformation, "Notice"
End If
Resume FileExistsExit
End Function
-
If the Kill keyword isn't turning blue, doesn't that mean that VB isn't recognizing it as an internal word?
It isn't turning blue by the way. . .
I'm using Visual Studio 6 SP4 by the way. . .don't know if that'll help.
-
Its not supposed to. Type it in small letters, if it turns it into Kill then its working