Solved

rename statement?

Posted on 2001-06-08
7
370 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
Comment Utility
Name oldpathname As newpathname

0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
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 49

Expert Comment

by:Ryan Chong
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:Microsoft
Comment Utility
name file1 as file2
0
 
LVL 1

Expert Comment

by:sb8gq
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now