VB 6.0 how to delete a file in the code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yoda
    Contributor
    • Dec 2006
    • 291

    VB 6.0 how to delete a file in the code?

    i would like to know what the delete code would be for VB 6.0. like if i want to delete a file called text3.txt on the C:\ drive, what would be the code to get rid of it.

    just trying to get so information i don't have.

    Thanks

    Yoda
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    You may be looking for the Output method here, provided you are hoping to clear data from a text file. Is this it Yoda?

    Hint: Append writes to the bottom of the file

    Comment

    • devonknows
      New Member
      • Nov 2006
      • 137

      #3
      Originally posted by yoda
      i would like to know what the delete code would be for VB 6.0. like if i want to delete a file called text3.txt on the C:\ drive, what would be the code to get rid of it.

      just trying to get so information i don't have.

      Thanks

      Yoda
      The only thing shorter than getting the system object involved, is to use the kill command, this will delete the file even if the file is in use

      Code:
      Private Sub Command1_Click()
          Call Kill("c:\text.txt") 'Will delete c:\text.txt even if its in use
      End Sub
      Like i say the only other way is to use an object but if its just to delete the odd file then id use kill to be honest,

      hope this help
      kind regards
      Devon.

      Comment

      • Dököll
        Recognized Expert Top Contributor
        • Nov 2006
        • 2379

        #4
        Good advice, Devon...

        Comment

        • devonknows
          New Member
          • Nov 2006
          • 137

          #5
          Originally posted by Dököll
          Good advice, Devon...
          Thank ye kindly :), was just personal preference, i use kill quite a lot, for example when im running database applications, and when the program runs a database integrity check, if its corrupt just delete it, because kill deletes the file wether or not it in use you wont get any of that arm ache trying to code it in to close the connections and then you can jus shellexecute your db install prog and bobs your uncle as they say..

          Kind Regards as always
          Devon.

          Comment

          • Dököll
            Recognized Expert Top Contributor
            • Nov 2006
            • 2379

            #6
            Regards indeed, Devon, thanks. Nice of you to fill in your fine tunes. should help Yoda a great deal, whichever way he wants to go about this. Isn't programming great? The back and front end of it...

            Comment

            • RJMac
              New Member
              • Mar 2007
              • 9

              #7
              One little question - will Kill send the file to the re-cycle bin, or just get rid of it, as I would find it would be useful to be able to send files to the re-cycle bin...

              Comment

              • devonknows
                New Member
                • Nov 2006
                • 137

                #8
                Originally posted by RJMac
                One little question - will Kill send the file to the re-cycle bin, or just get rid of it, as I would find it would be useful to be able to send files to the re-cycle bin...
                No, im afraid the Kill(Filename) command will just delete it completely, how ever the link below will take you to a developer fusion example and will give you the basics of sending it to the recycle bin

                http://www.developerfu sion.co.uk/show/120/

                Hope this helps you
                Kind Regards
                Devon

                Comment

                • devonknows
                  New Member
                  • Nov 2006
                  • 137

                  #9
                  Thank ye very much Dököll, i myself am still quite new to programming, im good with the problem solving side of it, and what things do but i can never remember the code as im doing it, can be most annoying :D.

                  Kind Regards
                  Devon.

                  Comment

                  • yoda
                    Contributor
                    • Dec 2006
                    • 291

                    #10
                    Originally posted by devonknows
                    Thank ye very much Dököll, i myself am still quite new to programming, im good with the problem solving side of it, and what things do but i can never remember the code as im doing it, can be most annoying :D.

                    Kind Regards
                    Devon.
                    yes u do give very good advice but do u have to have
                    Code:
                     Call Kill
                    in the code or just kill cuz if its just kill then i got it right but if u have to put call kill then thanks for the code.

                    Comment

                    • devonknows
                      New Member
                      • Nov 2006
                      • 137

                      #11
                      Originally posted by yoda
                      yes u do give very good advice but do u have to have
                      Code:
                       Call Kill
                      in the code or just kill cuz if its just kill then i got it right but if u have to put call kill then thanks for the code.
                      You dont have to use Call, i like to use it as it helps keep the code neat, for example instead of using...
                      Code:
                      MsgBox "This is a message", vbInformation, "Read Below"
                      you can keep it all together and then you know were it belongs

                      Code:
                      Call MsgBox("This is a Message", vbinformation, "Read Below")
                      Its just something i picked up when i was learning to program in the begining, and i believe that it makes the code alot neater and plus it gives you a quicker way to search through all your function calls, just by finding text "call" and so you dont have it all seperated, personal preference, but to your question, no you dont have to use "Call".

                      Kind Regards and Thank you for the comment.
                      Devon.

                      Comment

                      • yoda
                        Contributor
                        • Dec 2006
                        • 291

                        #12
                        no no thank you for answering my question thanks. and your welcome.

                        Comment

                        • Dököll
                          Recognized Expert Top Contributor
                          • Nov 2006
                          • 2379

                          #13
                          Originally posted by devonknows
                          No, im afraid the Kill(Filename) command will just delete it completely, how ever the link below will take you to a developer fusion example and will give you the basics of sending it to the recycle bin

                          http://www.developerfu sion.co.uk/show/120/

                          Hope this helps you
                          Kind Regards
                          Devon
                          Quite welcome, Devon, always keep copies of my code, just in case I am 90 and still want to code :-)

                          In a bit!

                          Dököll

                          Comment

                          • devonknows
                            New Member
                            • Nov 2006
                            • 137

                            #14
                            Originally posted by Dököll
                            Quite welcome, Devon, always keep copies of my code, just in case I am 90 and still want to code :-)

                            In a bit!

                            Dököll
                            i have a little red book were i keep my references, for example the developer fusion link i left with the full registry etc, i have it written in my little red book, sounds a bit evil that dont it, My Little Red Book! hehe thanks Dököll

                            Kind Regards
                            Devon

                            Comment

                            • Dököll
                              Recognized Expert Top Contributor
                              • Nov 2006
                              • 2379

                              #15
                              Not a bit evil, Devon, besides, think of the relief when the "little red book" saves you. I actually email reminders to myself when I have updated my code, make it more robust. The old code lives, surely, hidden in storage, but it is the new reminders that give me that evilish but yet triumphant sigh of relief, when it works flawlessly. I think we're entitled :-)

                              Oh, Dev fusion is a great site, and I agree. No gimmicks...

                              Talk soon!

                              Dököll

                              Comment

                              Working...