Solved

Rename the File Name

Posted on 2000-04-14
14
269 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now