Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

rename statement?

Posted on 2001-06-08
7
Medium Priority
?
385 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 160 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 54

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

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

876 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