rename statement?

Hi,

How to do something like
Rename file1 file2
in VB program?
learnAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
deightonConnect With a Mentor Commented:
Name oldpathname As newpathname

0
 
deightonCommented:
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
 
Ryan ChongCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
MicrosoftCommented:
name file1 as file2
0
 
sb8gqCommented:
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
 
KoothanCommented:
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
 
learnAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.