Visual Basic - Question

lieb39

Apple lover, PC User
Joined
27 Nov 2002
Messages
526
Is it possible in Visual Basic to rename, overright or delete a file on the hard drive? How? (Step by step is the best...)

Thanks.:)
 
Sure there is.

Use the Name statement to rename a file.

Use Kill to delete a file.

VB will overwrite files automatically. That's why
it's good practice to check for the existance of the
file and ask the user if the want to overwrite it.

Seach VB Help for Name and Kill
 
Oh no no no no no.

There is a much better, and safer way to rename/delete/copy/move files in VB.

Depends on your VB version, assuming VB6 you want to look at the File System Object (check it out on msdn.microsoft.com or www.vbcode.com).

name and kill do work, but you have very little control over what they do. The FSO also give you a better error message when a file is in use etc...

Have fun!
 
Open notepad, copy this as test.vbs and save. Double click it to run!

Const Path = "test.txt" 'Name of new file
Const TempPath = "test.tmp" 'Name of a temp file

Set fs = CreateObject("Scripting.FileSystemObject")
Set outFile = fs.CreateTextFile(TempPath, True) 'Create the temp file
outFile.write "Hello dude!" 'Write a line
outFile.close 'Close the file

fs.CopyFile TempPath, Path 'Copy one file to another file of a different name
fs.DeleteFile(TempPath) 'Delete the temp file
 
File System Object assumes a couple of things.

1. A more recent version of VB
2. A slightly more experienced VB programmer.

I find it better to start people off with the basics.

I will agree that is offers better error handling, but
most new programmers don't have an understanding
of the importance of that anyway.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back