Computing.Net > Forums > Programming > VB6 File rename help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VB6 File rename help

Reply to Message Icon

Name: 104625
Date: May 4, 2003 at 04:38:23 Pacific
OS: XP, 2000, 95
CPU/Ram: p4
Comment:

Ok I have a simple VB program (i am a newbie so be gentle with the comments). Basically I have a small interface tha allows the user to browse the directories for a file. They then highlight the file, which appears in text1. In text2 they have an alternative name to the file .Then click the command button which in turn changes the filename from what was in text1 to text2. However I am having a bit of trouble. Everything works fine until I click the change file name, it comes up with the message box to confirm the change and when I do it has a run time error 53 FILE NOT FOUND. All I can think of is that using Name Text1.text As Text2.text is just not working with variable names. The code is below for the command button. If anyone is able to help would be really appreciative.

Private Sub Command1_Click()
If MsgBox("Do you want want to rename " & Text1.Text, vbOKCancel, "Rename?") = vbOK Then
Name Text1.Text As Text2.Text
End If

Text1.Text = ""
File1.Refresh
End Sub



Sponsored Link
Ads by Google

Response Number 1
Name: Burbble
Date: May 5, 2003 at 10:27:07 Pacific
Reply:

I'll assume that you are using a combination of a directory list and a file list control for the user to locate the file. With that assumption, you can use the following code in place of the line starting "Name " :

Name File1.Path & "\" & Text1.Text As File1.Path & "\" & Text2.Text

File1 is the file listbox where the user has selected the file. The problem with the code as you have it is that VB assumes a directory if you omit it when trying to access a file (I think either the root directory or App.Path).
Also, the above code won't work properly if the file is in the root directory (such as C:\). If you want it to, you will need to use this instead:

If Right(File1.Path, 1) = "\" Then
Name File1.Path & Text1.Text As File1.Path & Text2.Text
Else
Name File1.Path & "\" & Text1.Text As File1.Path & "\" & Text2.Text
End If

If you have further questions don't hesitate to ask

-Burbble


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB6 File rename help

Batch file Renaming Help www.computing.net/answers/programming/batch-file-renaming-help/15827.html

File Renaming www.computing.net/answers/programming/file-renaming/8237.html

File rename in CMD or Bat script www.computing.net/answers/programming/file-rename-in-cmd-or-bat-script/14672.html