Link to home
Start Free TrialLog in
Avatar of kennethan
kennethan

asked on

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.


Avatar of hatem72
hatem72

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 ...
What about using the plain old Name Statement...

   Name oldpathname As newpathname


See the help pages...


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

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

ouch  <ewg>

mcrider is right name x as y
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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.
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.
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.
Avatar of kennethan

ASKER

Answer accepted
Thanks for the points! Glad I could help!


Cheers!®©