Reply
Old January 31st, 2003 Top | #1
 
lieb39's Avatar
Apple lover, PC User
Joined: November 2002
Location: Australia
Posts: 526
Reputation: 0
Power: 121

Question Visual Basic - Question

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.

Did a post help you, or solve a problem you were having?
Click the button under the member's avatar to increase his/her reputation, and to encourage useful posts on the forum.
lieb39 is offline   Reply With Quote
Old February 6th, 2003 Top | #2
 
XPletive's Avatar
bbbb-ring...
Joined: December 2001
Posts: 237
Reputation: 0
Power: 130

Default

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

XPletive is offline   Reply With Quote
Old February 11th, 2003 Top | #3
EventHorizon
 
EventHorizon's Avatar
Unregistered
Posts: n/a

Default

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!
  Reply With Quote
Old February 14th, 2003 Top | #4
 
a1ehouse's Avatar
Chamone M*tha Fu*ka
Joined: May 2002
Posts: 288
Reputation: 10
Power: 124

Default

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

...it maekesh me do a shecks wee...

a1ehouse is offline   Reply With Quote
Old February 18th, 2003 Top | #5
 
XPletive's Avatar
bbbb-ring...
Joined: December 2001
Posts: 237
Reputation: 0
Power: 130

Default

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.

XPletive is offline   Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with visual basic 6 saithe Web Design & Coding 1 December 28th, 2005 6:20am
visual basic.net help GhoulScout Web Design & Coding 13 December 16th, 2004 1:12am
Visual Basic 6 adamg Web Design & Coding 3 November 13th, 2003 5:35am
Visual Basic JJH35 Web Design & Coding 2 January 31st, 2003 2:41pm
[B]visual basic 6.0[/B] ..easy question for those who know about it 50Cper23 Web Design & Coding 4 November 1st, 2002 11:27pm