?
Solved

Rename the File Name

Posted on 2000-04-14
14
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 45 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 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