Solved

Rename the File Name

Posted on 2000-04-14
14
272 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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