Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Rename file without tag to text file


Reply
 
Thread Tools Display Modes
  #1  
Old 11-17-2004, 08:48 PM
Newhire Newhire is offline
Newcomer
 
Join Date: Oct 2004
Posts: 24
Default Rename file without tag to text file


Hi pros,

I'm developing one tool. In which, I want to rename a file without tag (such as 03292004 - this file can be opened by Notepad) to a text taged file (such as 03292004.txt).

I used this syntax: "Name sName as sRename" but it's error.
(sName="C:\03292004" - sRename="C:\03292004")

I used full path in sName & sRename.

Please tell me how can I fix this error.

Thanks so much first for your attention.

Newhire
__________________
Money is not problem, just no money is a big problem
Reply With Quote
  #2  
Old 11-17-2004, 09:15 PM
Gruff's Avatar
Gruff Gruff is online now
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,917
Default

Not sure what you are saying under the line containing 'syntax:', however, to append a "txt" file extention (What you are calling a tag) to a file that does not have one. You could use the following subroutine.

Code:
Option Explicit Private Sub Add_Txt_Extension(byval sFileName as string) Name sFileName as sFileName & ".txt" End Sub

Of course you may wish to check for an existing file extension inside the sub before you preform the rename. You might end up with something like "c:\bob.txt.txt"

~T
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #3  
Old 11-17-2004, 09:34 PM
Newhire Newhire is offline
Newcomer
 
Join Date: Oct 2004
Posts: 24
Default Text file rename

Gruff,

Thanks for your soon support, but I cannot fix the problem.

The error I receive is below:

Run-time error '5':
Invalid procedure call or argument


If you know, please tell me how to fix it!
Thanks again for your passion.

New hire.
__________________
Money is not problem, just no money is a big problem
Reply With Quote
  #4  
Old 11-17-2004, 09:47 PM
Gruff's Avatar
Gruff Gruff is online now
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,917
Default

Try the following. Create a text file on "C:\" with note pad called bob.txt

Use Window's Explorer to rename it to Bob (take off the .txt)

Open a new VB6 standard project with a blank form. Put a textbox and a command button on the form.

Double Click on the empty form.

Delete all the code in the Code window and paste the following:

Code:
'-------- Option Explicit Private Sub Form_Load() Text1.Text = "c:\bob" End Sub Private Sub Command1_Click() Call Add_Txt_Extension(Text1.Text) End Sub Private Sub Add_Txt_Extension(ByVal sFileName As String) Name sFileName As sFileName & ".txt" End Sub '--------

When you run the project and press the command button it should rename the file.
Go check with Window's Explorer to see it rename c:\bob to c:\bob.txt

Works fine on my pc.

~T
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #5  
Old 11-17-2004, 10:00 PM
Newhire Newhire is offline
Newcomer
 
Join Date: Oct 2004
Posts: 24
Default Text file rename

Gruff,

I'm really appreciate your support.

I'm now using MS Access XP. But there's one problem I found in debug mode.

That's when I use Name <oldFilename> As <newFilename>, when I retrieve value of Name, I receive value is name of form or name of application (such as frmRename or "Microsoft Access").

I think the problem is the library. I look for Name in Help but there's nothing about the procedure, just have Name in property.

Can you got me. Please help if you can.

New hire.
__________________
Money is not problem, just no money is a big problem
Reply With Quote
  #6  
Old 11-17-2004, 10:29 PM
Gruff's Avatar
Gruff Gruff is online now
Bald Mountain Survivor

Super Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,917
Default

Okay, I fired up Access. (Would have been nice to know that is what you were using. )

Even though I was able to get the routine to work for me I think I've heard about this sort of thing with Access before. It is defaulting to a property title (.Name) instead of using the VBA (Name statement.) I looked at the VBA objects with the Object View Tool. (Top of your tool bar.) and found a top level object called FileSystem) It has quite a few file manipulation methods. Unreasonable it does not seem to have a rename, However the following should work where you copy the file to a new name then delete the original.

With VBA.FileSystem
.FileCopy <filename1>,<filename2>
.Kill <filename1>
End With

Good luck,

~T
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #7  
Old 11-18-2004, 08:47 PM
Newhire Newhire is offline
Newcomer
 
Join Date: Oct 2004
Posts: 24
Default Text file rename

I'm sorry Gruff for not saying that I use MS Access first,

But I repaired it successfully. The reason is I was read from a text file to get the content within it. The content is the file name of another file.
So when I read it, there's 2 blank chars at the end of the content.

I repaired it & now I can use 2 ways as you showed me:
1. Name <old path> As <new path>
2. FileCopy & Kill

In the first way, I think MS Access will look for the right syntax with the procedure Name in VBA first, if there's any error, it will redirect to use method in other library (not VBA).

Gruff, I want to thank so much for your passion & your great support.

Bye for now and hope to see you another time (when either me or you have problem).

New hire
__________________
Money is not problem, just no money is a big problem
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->