Solved

Rename the File Name

Posted on 2000-04-14
14
270 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now