Rename the File Name

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.


kennethanAsked:
Who is Participating?
 
mcriderConnect With a Mentor Commented:
kennethan,

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

   Name oldpathname As newpathname



Cheers!®©
0
 
hatem72Commented:
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
 
mcriderCommented:
What about using the plain old Name Statement...

   Name oldpathname As newpathname


See the help pages...


Cheers!®©
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
gcs001Commented:
mcrider has it right - just remember to close the file before renaming it!
0
 
TheJamesWoodCommented:
strs = "move c:\t.txt c:\a.txt"
retval = Shell(strs, 1)

0
 
mcriderCommented:
TheJamesWood.... Come on... Shell?? <LOL>
0
 
stefanxCommented:
Agree with mcrider (about the shell) <ROFLMAO>. Name X as Y is the way to go.
0
 
vikiingCommented:
>>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
 
fibdevCommented:
shell ...

ouch  <ewg>

mcrider is right name x as y
0
 
vikiingCommented:
>>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
 
TheJamesWoodCommented:
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
 
csameer1Commented:
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
 
kennethanAuthor Commented:
Answer accepted
0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!®©
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.