By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,096 Members | 1,348 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,096 IT Pros & Developers. It's quick & easy.

VB 6.0 how to delete a file in the code?

yoda
100+
P: 291
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
Mar 21 '07 #1
Share this Question
Share on Google+
16 Replies


Dököll
Expert 100+
P: 2,364
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
Mar 21 '07 #2

devonknows
100+
P: 137
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command1_Click()
  3.     Call Kill("c:\text.txt") 'Will delete c:\text.txt even if its in use
  4. End Sub
  5.  
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.
Mar 21 '07 #3

Dököll
Expert 100+
P: 2,364
Good advice, Devon...
Mar 21 '07 #4

devonknows
100+
P: 137
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.
Mar 21 '07 #5

Dököll
Expert 100+
P: 2,364
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...
Mar 21 '07 #6

P: 9
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...
Mar 21 '07 #7

devonknows
100+
P: 137
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.developerfusion.co.uk/show/120/

Hope this helps you
Kind Regards
Devon
Mar 21 '07 #8

devonknows
100+
P: 137
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.
Mar 21 '07 #9

yoda
100+
P: 291
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
Expand|Select|Wrap|Line Numbers
  1.  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.
Mar 21 '07 #10

devonknows
100+
P: 137
yes u do give very good advice but do u have to have
Expand|Select|Wrap|Line Numbers
  1.  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...
Expand|Select|Wrap|Line Numbers
  1. MsgBox "This is a message", vbInformation, "Read Below"
  2.  
you can keep it all together and then you know were it belongs

Expand|Select|Wrap|Line Numbers
  1. Call MsgBox("This is a Message", vbinformation, "Read Below")
  2.  
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.
Mar 21 '07 #11

yoda
100+
P: 291
no no thank you for answering my question thanks. and your welcome.
Mar 21 '07 #12

Dököll
Expert 100+
P: 2,364
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.developerfusion.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
Mar 21 '07 #13

devonknows
100+
P: 137
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
Mar 21 '07 #14

Dököll
Expert 100+
P: 2,364
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
Mar 22 '07 #15

P: 9
DevonKnows - thanks for the recycle bin information, it's very much appreciated!!
Mar 22 '07 #16

devonknows
100+
P: 137
DevonKnows - thanks for the recycle bin information, it's very much appreciated!!
Woo two birds with one stone hehe, call me Devon. Glad i could help

Kind Regards
Devon.
Mar 27 '07 #17

Post your reply

Sign in to post your reply or Sign up for a free account.