Solved

Rename the File Name

Posted on 2000-04-14
14
273 Views
Last Modified: 2010-05-02
I open the Test1.txt file in the D:\temp directory and do some process in the program. After process, if I want to rename the Test1.txt file to, for example, Test9.txt, how should I do?

<code>
Open "D:\temp\Test1.txt" For Input As #1
... program code

How do you rename the file? Except the method of regenerating the new file and "kill" the old file.


0
Comment
Question by:kennethan
  • 4
  • 2
  • 2
  • +6
14 Comments
 
LVL 6

Expert Comment

by:hatem72
ID: 2718120
this code will Renames files in a folder. Searches for a string in the filename and renames it with another (or blank = erases) Very simple code :

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=5974

Hope Help ...
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2718201
What about using the plain old Name Statement...

   Name oldpathname As newpathname


See the help pages...


Cheers!®©
0
 
LVL 4

Expert Comment

by:gcs001
ID: 2718398
mcrider has it right - just remember to close the file before renaming it!
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Expert Comment

by:TheJamesWood
ID: 2718511
strs = "move c:\t.txt c:\a.txt"
retval = Shell(strs, 1)

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2718636
TheJamesWood.... Come on... Shell?? <LOL>
0
 
LVL 8

Expert Comment

by:stefanx
ID: 2718708
Agree with mcrider (about the shell) <ROFLMAO>. Name X as Y is the way to go.
0
 
LVL 3

Expert Comment

by:vikiing
ID: 2718862
>>strs = "move c:\t.txt c:\a.txt"
>>retval = Shell(strs, 1)

Each time I see people working this way, thick teardrops go rolling down my face... :~~(
0
 
LVL 3

Expert Comment

by:fibdev
ID: 2719638
shell ...

ouch  <ewg>

mcrider is right name x as y
0
 
LVL 14

Accepted Solution

by:
mcrider earned 15 total points
ID: 2720006
kennethan,

You still there?? As I stated before...

   Name oldpathname As newpathname



Cheers!®©
0
 
LVL 3

Expert Comment

by:vikiing
ID: 2720275
>>Name oldpathname As newpathname

NAME instruction has a hidden advantage: both paths (old and new) can include DIFFERENT directories, making NAME instruction so powerful as MOVE (DOS) instruction; this is, NAME can pick up a file from a certain dir and hang it on another one. Nice, ¿isn't it?.

The only (and obvious) limit: NAME doesn't work across different devices.
0
 

Expert Comment

by:TheJamesWood
ID: 2725084
To answer a question, one should compare and contrast.

Gurus should learn to temper their opinions and offer information that is useful: e.g., vikking's remarks.

There is more than one way to do things, and should not one know them all, rather than say I know one truth.

Open "D:\temp\Test1.txt" For Input As #1

.... tears went down my face...  fso's are cool.
0
 
LVL 1

Expert Comment

by:csameer1
ID: 2852779
though out of context,i would like to remind that fso will not run if the windowss scripting host is removed(love virus scare).It will hang if you try to open .bmp by mistake.
0
 

Author Comment

by:kennethan
ID: 2875186
Answer accepted
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2875523
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question