• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Visual Basic - Question

lieb39

Apple lover, PC User
#1
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.:)
 

XPletive

bbbb-ring...
#2
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
 
E

EventHorizon

Guest
#3
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!
 

a1ehouse

Chamone M*tha Fu*ka
#4
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
 
#5
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies