Solved

rename statement?

Posted on 2001-06-08
7
372 Views
Last Modified: 2010-05-02
Hi,

How to do something like
Rename file1 file2
in VB program?
0
Comment
Question by:learn
7 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 40 total points
ID: 6167185
Name oldpathname As newpathname

0
 
LVL 18

Expert Comment

by:deighton
ID: 6167191
This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist.

Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE"     ' Define filenames.
Name OldName As NewName     ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName     ' Move and rename file.
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6167221
Hi, try this:

Private Sub Command1_Click()
    Sourcepath = "C:\windows\desktop\"
    Targetpath = "C:\windows\desktop\"
   
    FileCopy Sourcepath & "db1.mdb", Targetpath & "db2.mdb"
    SetAttr Sourcepath & "db1.mdb", vbNormal
    Kill Sourcepath & "db1.mdb"
End Sub
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 2

Expert Comment

by:Microsoft
ID: 6173555
name file1 as file2
0
 
LVL 1

Expert Comment

by:sb8gq
ID: 6174066
OR

you could use the FileSystemObject which is part of the Microsoft Sripting Library . (Add a reference to Microsoft Sripting Libraryin project references and use the following code

Dim fso As FileSystemObject
Set fso = New FileSystemObject
   
fso.MoveFile (SourceFile, DestFile)


Steve
0
 

Expert Comment

by:Koothan
ID: 6180679
write the following code snippet in whatever event u want

Open "C:\renamed.bat" For Output As #1
Print #1, "rename c:\testren.txt rentest.txt"
Close #1

dProcessId = Shell("c:\renamed.bat", vbHide)

this will do the same as that of the rename command in DOS
0
 

Author Comment

by:learn
ID: 6200218
Thanks a lot for all your helps.
I am giving the points to deiqhton who posted one of the correct answers in the first time .....not because he/she posted that as an answer though:-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 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