learn
asked on
rename statement?
Hi,
How to do something like
Rename file1 file2
in VB program?
How to do something like
Rename file1 file2
in VB program?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
name file1 as file2
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
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
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
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
ASKER
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:-)
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:-)
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.