 |
 |

11-17-2004, 08:48 PM
|
|
Newcomer
|
|
Join Date: Oct 2004
Posts: 24
|
|
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
|

11-17-2004, 09:15 PM
|
 |
Bald Mountain Survivor
Super Moderator * Expert *
|
|
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,917
|
|
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
|

11-17-2004, 09:34 PM
|
|
Newcomer
|
|
Join Date: Oct 2004
Posts: 24
|
|
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
|

11-17-2004, 09:47 PM
|
 |
Bald Mountain Survivor
Super Moderator * Expert *
|
|
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,917
|
|
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
|

11-17-2004, 10:00 PM
|
|
Newcomer
|
|
Join Date: Oct 2004
Posts: 24
|
|
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
|

11-17-2004, 10:29 PM
|
 |
Bald Mountain Survivor
Super Moderator * Expert *
|
|
Join Date: Aug 2003
Location: Oregon, USA
Posts: 5,917
|
|
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
|

11-18-2004, 08:47 PM
|
|
Newcomer
|
|
Join Date: Oct 2004
Posts: 24
|
|
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
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|