Results 1 to 9 of 9

Thread: Deleting Files

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    5

    Angry

    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!!

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Kill yourFileName

    will delete your file

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    To delete a file use :
    Code:
    Kill "filepath"
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4
    Guest
    First you should check if it exists else, you'll get an error.
    Code:
    If Dir$("This File") <> "" Then Kill "This file"

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    5

    Cool 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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    5

    Angry 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.

  7. #7
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    5
    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.

  9. #9
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Its not supposed to. Type it in small letters, if it turns it into Kill then its working

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width